diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-29 09:18:45 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-29 09:18:45 +0800 |
| commit | 4aa6fabbb594af1889778ff7f01ae3193dc08b1d (patch) | |
| tree | f25dea86c382d94bb005239001ef99da25fded37 /src/LivingVillage.Desktop.Tests/P68MapSnapshotTests.fs | |
| parent | a578791b0dd8ca95fba3af6f3c2f39c816bd7e52 (diff) | |
| download | living-village-4aa6fabbb594af1889778ff7f01ae3193dc08b1d.tar.gz | |
p68: 512×384 整图离线渲染截图证据
- MapSnapshot:MapGen.Result 纯 CPU 渲染为整图 PNG(每瓦片 8px,自包含
IHDR/IDAT/IEND + CRC32 + ZLibStream,无外部图像依赖);调色板覆盖
河流/主路/农田/民居屋顶/小径/桥/树丛
- Program.fs:LV_P68_MAPSHOT=1 钩子用 paramsForSize 512 384 seed=4242 生成并
离线渲染整图后退出(headless,不需图形设备)
- P68MapSnapshotTests(3 例,红先):尺寸/PNG 签名、要素像素存在、两次渲染逐字节一致
- scripts/analyze-p68.py:尺寸/调色板像素/无黑白大块/missing_glyph_slots=0/确定性
- Desktop 336/336、Kernel 119/119;digest 953775FA…7F6C ×3 PASS;未动 Kernel/Sim
Diffstat (limited to 'src/LivingVillage.Desktop.Tests/P68MapSnapshotTests.fs')
| -rw-r--r-- | src/LivingVillage.Desktop.Tests/P68MapSnapshotTests.fs | 54 |
1 files changed, 54 insertions, 0 deletions
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") |
