diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-22 03:39:05 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-22 03:39:05 +0800 |
| commit | 847a12bd7029302d95c2b725758c7681b57235dc (patch) | |
| tree | 89c8449334e26f3683e854017ae7fe00fb4385dd /src/LivingVillage.Desktop.Tests | |
| parent | 8366a2c4cec9e42c6d8efeaf986e2c4521b3da70 (diff) | |
| download | living-village-847a12bd7029302d95c2b725758c7681b57235dc.tar.gz | |
feat(perf): 帧率采样汇总纯函数 + 测试(P21)
- PerformanceSummary.summarize:丢弃 warmup 后求每秒 FPS 的均值/最低/最高,
空样本返回 None;含 3 条单测(TDD)。
Diffstat (limited to 'src/LivingVillage.Desktop.Tests')
| -rw-r--r-- | src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj | 1 | ||||
| -rw-r--r-- | src/LivingVillage.Desktop.Tests/PerformanceSummaryTests.fs | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj index 87e9e9d..a0c98b0 100644 --- a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj +++ b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj @@ -12,6 +12,7 @@ <Compile Include="P16UiTests.fs" /> <Compile Include="PrototypeTests.fs" /> <Compile Include="MapGenTests.fs" /> + <Compile Include="PerformanceSummaryTests.fs" /> <Compile Include="M3BatchOutputTests.fs" /> <Compile Include="SampleTests.fs" /> </ItemGroup> diff --git a/src/LivingVillage.Desktop.Tests/PerformanceSummaryTests.fs b/src/LivingVillage.Desktop.Tests/PerformanceSummaryTests.fs new file mode 100644 index 0000000..cd7c3b1 --- /dev/null +++ b/src/LivingVillage.Desktop.Tests/PerformanceSummaryTests.fs @@ -0,0 +1,34 @@ +namespace LivingVillage.Desktop.Tests + +open System +open Microsoft.VisualStudio.TestTools.UnitTesting +open LivingVillage.Desktop + +[<TestClass>] +type PerformanceSummaryTests () = + + let close (expected: float) (actual: float) = + Assert.IsTrue(abs (expected - actual) < 0.0001, sprintf "expected %f but got %f" expected actual) + + [<TestMethod>] + member _.SummarizeDropsWarmupAndReportsMeanMinMax () = + match PerformanceSummary.summarize 2 [ 10.0; 20.0; 30.0; 40.0 ] with + | None -> Assert.Fail("expected a summary") + | Some summary -> + Assert.AreEqual<int>(2, summary.Count) + close 35.0 summary.Mean + close 30.0 summary.Min + close 40.0 summary.Max + + [<TestMethod>] + member _.SummarizeReturnsNoneWhenNoRealSampleRemains () = + Assert.IsTrue((PerformanceSummary.summarize 5 [ 1.0; 2.0 ]).IsNone) + Assert.IsTrue((PerformanceSummary.summarize 0 []).IsNone) + + [<TestMethod>] + member _.SummarizeWithZeroWarmupKeepsEverySample () = + match PerformanceSummary.summarize 0 [ 60.0; 59.5; 61.0 ] with + | None -> Assert.Fail("expected a summary") + | Some summary -> + Assert.AreEqual<int>(3, summary.Count) + close 59.5 summary.Min |
