Files
.vs
Assets
Library
APIUpdater
Artifacts
Bee
BuildPlayerData
PackageCache
com.unity.collab-proxy@2.5.2
com.unity.editorcoroutines@1.0.0
com.unity.ext.nunit@1.0.6
com.unity.feature.development@1.0.1
com.unity.ide.rider@3.0.31
com.unity.ide.visualstudio@2.0.22
com.unity.ide.vscode@1.2.5
com.unity.modules.ai@1.0.0
com.unity.modules.androidjni@1.0.0
com.unity.modules.animation@1.0.0
com.unity.modules.assetbundle@1.0.0
com.unity.modules.audio@1.0.0
com.unity.modules.cloth@1.0.0
com.unity.modules.director@1.0.0
com.unity.modules.imageconversion@1.0.0
com.unity.modules.imgui@1.0.0
com.unity.modules.jsonserialize@1.0.0
com.unity.modules.particlesystem@1.0.0
com.unity.modules.physics2d@1.0.0
com.unity.modules.physics@1.0.0
com.unity.modules.screencapture@1.0.0
com.unity.modules.subsystems@1.0.0
com.unity.modules.terrain@1.0.0
com.unity.modules.terrainphysics@1.0.0
com.unity.modules.tilemap@1.0.0
com.unity.modules.ui@1.0.0
com.unity.modules.uielements@1.0.0
com.unity.modules.umbra@1.0.0
com.unity.modules.unityanalytics@1.0.0
com.unity.modules.unitywebrequest@1.0.0
com.unity.modules.unitywebrequestassetbundle@1.0.0
com.unity.modules.unitywebrequestaudio@1.0.0
com.unity.modules.unitywebrequesttexture@1.0.0
com.unity.modules.unitywebrequestwww@1.0.0
com.unity.modules.vehicles@1.0.0
com.unity.modules.video@1.0.0
com.unity.modules.vr@1.0.0
com.unity.modules.wind@1.0.0
com.unity.modules.xr@1.0.0
com.unity.performance.profile-analyzer@1.2.2
Documentation~
Editor
Tests
Editor
FrameTimeGraphSelectionTests.cs
FrameTimeGraphSelectionTests.cs.meta
MarkerDataAPITests.cs
MarkerDataAPITests.cs.meta
MicrosecondsUnitsTest.cs
MicrosecondsUnitsTest.cs.meta
MillisecondsUnitsTest.cs
MillisecondsUnitsTest.cs.meta
ProfileAnalysisAPITests.cs
ProfileAnalysisAPITests.cs.meta
ProfileAnalyzerAPITests.cs
ProfileAnalyzerAPITests.cs.meta
ProfileAnalyzerBaseTest.cs
ProfileAnalyzerBaseTest.cs.meta
ProfileAnalyzerCaptureTests.cs
ProfileAnalyzerCaptureTests.cs.meta
ProfileAnalyzerEmptyTests.cs
ProfileAnalyzerEmptyTests.cs.meta
ProfileDataAPITests.cs
ProfileDataAPITests.cs.meta
ProfileDataTests.cs
ProfileDataTests.cs.meta
UnitsTestFixture.cs
UnitsTestFixture.cs.meta
Unity.Performance.Profile-Analyzer.EditorTests.asmdef
Unity.Performance.Profile-Analyzer.EditorTests.asmdef.meta
.tests.json
Editor.meta
.signature
CHANGELOG.md
CHANGELOG.md.meta
Editor.meta
LICENSE.md
LICENSE.md.meta
README.md
README.md.meta
Tests.meta
package.json
package.json.meta
com.unity.settings-manager@2.0.1
com.unity.test-framework@1.1.33
com.unity.testtools.codecoverage@1.2.6
com.unity.textmeshpro@3.0.6
com.unity.timeline@1.7.6
com.unity.ugui@1.0.0
com.unity.visualscripting@1.9.4
PackageManager
PlayModeViewStates
PlayerDataCache
ScriptAssemblies
Search
ShaderCache
SplashScreenCache
StateCache
UIElements
AnnotationManager
ArtifactDB
ArtifactDB-lock
BuildPlayer.prefs
BuildSettings.asset
EditorOnlyScriptingSettings.json
EditorOnlyVirtualTextureState.json
EditorSnapSettings.asset
EditorUserBuildSettings.asset
InspectorExpandedItems.asset
LastBuild.buildreport
LastSceneManagerSetup.txt
LibraryFormatVersion.txt
MonoManager.asset
SceneVisibilityState.asset
ScriptMapper
ShaderCache.db
SourceAssetDB
SourceAssetDB-lock
SpriteAtlasDatabase.asset
Style.catalog
expandedItems
ilpp.pid
Logs
Packages
ProjectSettings
UserSettings
obj
.vsconfig
Assembly-CSharp.Player.csproj
Assembly-CSharp.csproj
TM1.sln
Unity.CollabProxy.Editor.csproj
Unity.EditorCoroutines.Editor.csproj
Unity.Performance.Profile-Analyzer.Editor.csproj
Unity.PlasticSCM.Editor.csproj
Unity.Rider.Editor.csproj
Unity.Settings.Editor.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Model.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Mono.Reflection.csproj
Unity.TestTools.CodeCoverage.Editor.csproj
Unity.TextMeshPro.Editor.csproj
Unity.TextMeshPro.Player.csproj
Unity.TextMeshPro.csproj
Unity.Timeline.Editor.csproj
Unity.Timeline.Player.csproj
Unity.Timeline.csproj
Unity.VSCode.Editor.csproj
Unity.VisualScripting.Core.Editor.csproj
Unity.VisualScripting.Core.Player.csproj
Unity.VisualScripting.Core.csproj
Unity.VisualScripting.Flow.Editor.csproj
Unity.VisualScripting.Flow.Player.csproj
Unity.VisualScripting.Flow.csproj
Unity.VisualScripting.SettingsProvider.Editor.csproj
Unity.VisualScripting.Shared.Editor.csproj
Unity.VisualScripting.State.Editor.csproj
Unity.VisualScripting.State.Player.csproj
Unity.VisualScripting.State.csproj
Unity.VisualStudio.Editor.csproj
UnityEditor.TestRunner.csproj
UnityEditor.UI.csproj
UnityEngine.TestRunner.Player.csproj
UnityEngine.TestRunner.csproj
UnityEngine.UI.Player.csproj
UnityEngine.UI.csproj

137 lines
5.4 KiB
C#
Raw Normal View History

2025-01-17 13:10:20 +01:00
using NUnit.Framework;
using UnityEditor.Performance.ProfileAnalyzer;
using System.Collections.Generic;
public class MicrosecondsUnitsFixture : UnitsTestFixture
{
[SetUp]
public void SetupTest()
{
displayUnits = new DisplayUnits(Units.Microseconds);
}
}
public class MicrosecondsUnitsTest : MicrosecondsUnitsFixture
{
static TestData[] DecimalLimitValues = new TestData[]
{
new TestData(0.000000001f, "0.0"),
new TestData(0.00009f, "0.1"),
new TestData(0.0004f, "0.4"),
new TestData(0.0005f, "0.5"),
new TestData(0.0112f, "11.2"),
new TestData(0.0091f, "9.1"), // Show 1 decimal point for <100us
new TestData(0.1012f, "101"),
new TestData(1.0012f, "1001"),
new TestData(10.0012f, "10001"),
new TestData(100.0012f, "100001"),
new TestData(1000.0012f, "1000001"),
new TestData(10000.0012f, "10000000"), // Only 6 sf valid
new TestData(100000.0012f, "100000000"),
};
[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.000000001f, "1E-06"),
new TestData(0.00009f, "0.09"),
new TestData(0.0004f, "0.4"),
new TestData(0.0005f, "0.5"),
new TestData(0.0009f, "0.9"),
new TestData(0.0015f, "1.5"),
new TestData(0.0112f, "11.2"),
new TestData(0.0959f, "95.9"),
new TestData(0.1012f, "101"),
new TestData(1.0012f, "1001"),
new TestData(10.0012f, "10001"),
new TestData(100.0012f, "100001"),
new TestData(1000.0012f, "1000001"),
new TestData(10000.0012f, "10000000"), // Only 6 sf valid
new TestData(100000.0012f, "100000000"),
};
[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[] WithUnitsValues = new TestData[]
{
new TestData(0.000000001f, "0.0us"),
new TestData(0.00009f, "0.1us"),
new TestData(0.0004f, "0.4us"),
new TestData(0.0005f, "0.5us"),
new TestData(0.0015f, "1.5us"),
new TestData(0.0112f, "11.2us"),
new TestData(0.1012f, "101us"),
new TestData(1.0012f, "1001us"),
new TestData(10.0012f, "10001us"),
new TestData(100.0012f, "100001us"),
new TestData(1000.0012f, "1000001us"),
new TestData(10000.0012f, "10000000us"), // Only 6 sf valid
new TestData(100000.0012f, "100000000us"),
};
[Test]
public void WithUnits([ValueSource("WithUnitsValues")] 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.000000001f, "0.0"),
new TestData(0.00009f, "0.1"),
new TestData(0.0004f, "0.4"),
new TestData(0.0005f, "0.5"),
new TestData(0.0112f, "11.2"),
new TestData(0.1012f, "101"),
new TestData(1.0012f, "1001"),
new TestData(10.0012f, "10001"),
new TestData(100.0012f, "100ms"),
new TestData(1000.0012f, "1s"),
new TestData(10000.0012f, "10s"),
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[] WithUnitsLimitedTo5DigitsValuesAndShowFullValueWhenBelowZeroValues = new TestData[]
{
new TestData(0.000000001f, "0.001ns"),
new TestData(0.00009f, "0.09us"),
new TestData(0.0004f, "0.4us"),
new TestData(0.0005f, "0.5us"),
new TestData(0.0015f, "1.5us"),
new TestData(0.0112f, "11.2us"),
new TestData(0.1012f, "101.2us"),
new TestData(1.0012f, "1001.2us"),
new TestData(10.0012f, "10001us"),
new TestData(100.0012f, "100ms"),
new TestData(1000.0012f, "1s"),
new TestData(10000.0012f, "10s"), // Only 6 sf valid
new TestData(100000.0012f, "100s"),
};
[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);
}
}