diff options
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/P68MapSnapshotTests.fs | 54 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj index 2ea84b5..6d1a3e8 100644 --- a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj +++ b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj @@ -40,6 +40,7 @@ <Compile Include="P65RumorInquiryTests.fs" /> <Compile Include="P66TaskTargetTests.fs" /> <Compile Include="P67TaskTargetUiTests.fs" /> + <Compile Include="P68MapSnapshotTests.fs" /> <Compile Include="SampleTests.fs" /> </ItemGroup> diff --git a/src/LivingVillage.Desktop.Tests/P68MapSnapshotTests.fs b/src/LivingVillage.Desktop.Tests/P68MapSnapshotTests.fs new file mode 100644 index 0000000..4109aae --- /dev/null +++ b/src/LivingVillage.Desktop.Tests/P68MapSnapshotTests.fs @@ -0,0 +1,54 @@ +namespace LivingVillage.Desktop.Tests + +open Microsoft.VisualStudio.TestTools.UnitTesting +open LivingVillage.Desktop + +/// P68:512×384 整图离线渲染(MapSnapshot)的可验收护栏。 +/// 断言尺寸/要素像素存在性/确定性;调色板口径与 scripts/analyze-p68.py 一致。 +[<TestClass>] +type P68MapSnapshotTests () = + + let map = MapGen.generateWithSize 512 384 (uint64 4242) + + let be32 (bytes: byte array) (offset: int) : int = + (int bytes.[offset] <<< 24) + ||| (int bytes.[offset + 1] <<< 16) + ||| (int bytes.[offset + 2] <<< 8) + ||| int bytes.[offset + 3] + + let countColor (rgb: byte array) (color: byte * byte * byte) : int = + let r, g, b = color + let mutable count = 0 + let mutable i = 0 + while i < rgb.Length do + if rgb.[i] = r && rgb.[i + 1] = g && rgb.[i + 2] = b then count <- count + 1 + i <- i + 3 + count + + [<TestMethod>] + member _.RenderPngHasFullMapDimensions () = + let png = MapSnapshot.renderPng map 4 + let signature = [| 137uy; 80uy; 78uy; 71uy; 13uy; 10uy; 26uy; 10uy |] + CollectionAssert.AreEqual(signature, png.[0..7]) + Assert.AreEqual<string>("IHDR", System.Text.Encoding.ASCII.GetString(png.[12..15])) + Assert.AreEqual<int>(512 * 4, be32 png 16) + Assert.AreEqual<int>(384 * 4, be32 png 20) + + [<TestMethod>] + member _.RenderRgbContainsRiverRoadFarmAndBuildingPixels () = + let rgb = MapSnapshot.renderRgb map 8 + Assert.AreEqual<int>(512 * 8 * 384 * 8 * 3, rgb.Length) + Assert.IsTrue(countColor rgb (52uy, 110uy, 180uy) > 0, "river (water) pixels missing") + Assert.IsTrue( + countColor rgb (120uy, 168uy, 84uy) + countColor rgb (154uy, 186uy, 96uy) > 0, + "farmland pixels missing") + Assert.IsTrue(countColor rgb (214uy, 190uy, 128uy) > 0, "main-road pixels missing") + Assert.IsTrue(countColor rgb (196uy, 176uy, 120uy) > 0, "path pixels missing") + Assert.IsTrue(countColor rgb (58uy, 58uy, 70uy) > 0, "building roof pixels missing") + + [<TestMethod>] + member _.RenderIsByteIdenticalAcrossRuns () = + let first = MapSnapshot.renderPng map 8 + let second = MapSnapshot.renderPng (MapGen.generateWithSize 512 384 (uint64 4242)) 8 + CollectionAssert.AreEqual(first, second) + Assert.IsTrue(MapSnapshot.renderPng map 4 <> first, "different scale must produce a different image") |
