File size: 5,989 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | using NUnit.Framework;
using UnityEditor.Performance.ProfileAnalyzer;
using System.Collections.Generic;
public class MillisecondsUnitsFixture : UnitsTestFixture
{
[SetUp]
public void SetupTest()
{
displayUnits = new DisplayUnits(Units.Milliseconds);
}
}
public class MillisecondsUnitsTest : MillisecondsUnitsFixture
{
static TestData[] DecimalLimitValues = new TestData[]
{
new TestData(0.00000001f, "0.00"),
new TestData(0.0009f, "0.00"),
new TestData(0.004f, "0.00"),
new TestData(0.005f, "0.01"),
new TestData(0.1012f, "0.10"),
new TestData(1.0012f, "1.00"),
new TestData(10.0012f, "10.00"),
new TestData(100.0012f, "100.00"),
new TestData(1000.0012f, "1000.00"),
new TestData(10000.0012f, "10000.00"),
new TestData(100000.0012f, "100000.00"),
};
[Test]
public void DecimalLimit([ValueSource("DecimalLimitValues")] TestData testData)
{
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 0, showFullValueWhenBelowZero: false);
Assert.AreEqual(testData.expectedOutput, output);
}
static TestData[] ShowFullValueWhenBelowZeroValues = new TestData[]
{
new TestData(0.00000001f, "1E-08"),
new TestData(0.0009f, "0.0009"),
new TestData(0.004f, "0.004"),
new TestData(0.005f, "0.005"),
new TestData(0.01f, "0.01"),
new TestData(0.015f, "0.02"),
new TestData(0.1012f, "0.10"),
new TestData(1.0012f, "1.00"),
new TestData(10.0012f, "10.00"),
new TestData(100.0012f, "100.00"),
new TestData(1000.0012f, "1000.00"),
new TestData(10000.0012f, "10000.00"),
new TestData(100000.0012f, "100000.00"),
};
[Test]
public void ShowFullValueWhenBelowZero([ValueSource("ShowFullValueWhenBelowZeroValues")] TestData testData)
{
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 0, showFullValueWhenBelowZero: true);
Assert.AreEqual(testData.expectedOutput, output);
}
static TestData[] ShowUnitsValues = new TestData[]
{
new TestData(0.00000001f, "0.00ms"),
new TestData(0.0009f, "0.00ms"),
new TestData(0.004f, "0.00ms"),
new TestData(0.005f, "0.01ms"),
new TestData(0.1012f, "0.10ms"),
new TestData(1.0012f, "1.00ms"),
new TestData(10.0012f, "10.00ms"),
new TestData(100.0012f, "100.00ms"),
new TestData(1000.0012f, "1000.00ms"),
new TestData(10000.0012f, "10000.00ms"),
new TestData(100000.0012f, "100000.00ms"),
};
[Test]
public void ShowUnits([ValueSource("ShowUnitsValues")] TestData testData)
{
string output = displayUnits.ToString(testData.value, showUnits: true, limitToNDigits: 0, showFullValueWhenBelowZero: false);
Assert.AreEqual(testData.expectedOutput, output);
}
static TestData[] LimitedTo5DigitsValues = new TestData[]
{
new TestData(0.00000001f, "0.00"),
new TestData(0.0009f, "0.00"),
new TestData(0.004f, "0.00"),
new TestData(0.005f, "0.01"),
new TestData(0.1012f, "0.10"),
new TestData(1.0012f, "1.00"),
new TestData(10.0012f, "10.00"),
new TestData(100.0012f, "100.00"),
new TestData(1000.0012f, "1000.0"),
new TestData(10000.0012f, "10000"),
new TestData(100000.0012f, "100s"),
};
[Test]
public void LimitedTo5Digits([ValueSource("LimitedTo5DigitsValues")] TestData testData)
{
string output = displayUnits.ToString(testData.value, showUnits: false, limitToNDigits: 5, showFullValueWhenBelowZero: false);
Assert.AreEqual(testData.expectedOutput, output);
}
static TestData[] WithUnitsLimitedTo5DigitsValues = new TestData[]
{
new TestData(0.00000001f, "0.00ms"),
new TestData(0.0009f, "0.00ms"),
new TestData(0.004f, "0.00ms"),
new TestData(0.005f, "0.01ms"),
new TestData(0.1012f, "0.10ms"),
new TestData(1.0012f, "1.00ms"),
new TestData(10.0012f, "10.0ms"),
new TestData(100.0012f, "100ms"),
new TestData(1000.0012f, "1.00s"),
new TestData(10000.0012f, "10.0s"),
new TestData(100000.0012f, "100s"),
};
[Test]
public void WithUnitsLimitedTo5Digits([ValueSource("WithUnitsLimitedTo5DigitsValues")] TestData testData)
{
string output = displayUnits.ToString(testData.value, showUnits: true, limitToNDigits: 5, showFullValueWhenBelowZero: false);
Assert.AreEqual(testData.expectedOutput, output);
}
static TestData[] WithUnitsLimitedTo5DigitsValuesAndShowFullValueWhenBelowZeroValues = new TestData[]
{
new TestData(0.00000001f, "0.01ns"),
new TestData(0.0009f, "0.90us"),
new TestData(0.004f, "4.00us"),
new TestData(0.005f, "5.00us"),
new TestData(0.1012f, "0.1012ms"),
new TestData(1.0012f, "1.0012ms"),
new TestData(10.0012f, "10.001ms"),
new TestData(100.0012f, "100.00ms"),
new TestData(1000.0012f, "1000.0ms"),
new TestData(10000.0012f, "10000ms"),
new TestData(100000.0012f, "100.00s"),
};
[Test]
public void WithUnitsLimitedTo5DigitsAndShowFullValueWhenBelowZero([ValueSource("WithUnitsLimitedTo5DigitsValuesAndShowFullValueWhenBelowZeroValues")] TestData testData)
{
string output = displayUnits.ToString(testData.value, showUnits: true, limitToNDigits: 5, showFullValueWhenBelowZero: true);
Assert.AreEqual(testData.expectedOutput, output);
}
}
|