summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Kernel.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Kernel.Tests')
-rw-r--r--src/LivingVillage.Kernel.Tests/M6aTests.fs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/LivingVillage.Kernel.Tests/M6aTests.fs b/src/LivingVillage.Kernel.Tests/M6aTests.fs
index 91f0a10..7f8d5ea 100644
--- a/src/LivingVillage.Kernel.Tests/M6aTests.fs
+++ b/src/LivingVillage.Kernel.Tests/M6aTests.fs
@@ -161,6 +161,64 @@ type M6aTests () =
Assert.AreEqual<SimulationSpeed>(OneX, resumed.Speed)
[<TestMethod>]
+ member _.BoundsAreParameterizableAndClampMovementAtLargeMapEdge () =
+ Sim.configureBounds 512 384
+ try
+ let world = Sim.initialWorld (uint64 42)
+ let stepped = Sim.step { Input = { MoveX = 1.0f; MoveY = 1.0f } } world
+ // Legacy maps clamp within 64x48; at 512x384 the avatar is free to wander
+ // well past the old tile limits.
+ let maxX = float32 (Sim.mapWidthTiles * Sim.tilePixels - Sim.tilePixels)
+ let maxY = float32 (Sim.mapHeightTiles * Sim.tilePixels - Sim.tilePixels)
+ Assert.IsTrue(stepped.Avatar.Pos.X <= maxX)
+ Assert.IsTrue(stepped.Avatar.Pos.Y <= maxY)
+ Assert.AreEqual<int>(512, Sim.mapWidthTiles)
+ finally
+ Sim.configureBounds 64 48
+
+ [<TestMethod>]
+ member _.SaveV1LegacyStillReadable () =
+ let world = Sim.initialWorld (uint64 42)
+ WorldSave.saveToFile "p7-legacy-src.save" world
+ let modern = System.IO.File.ReadAllText "p7-legacy-src.save"
+ // v2 = version|w|h|body...; strip the two bounds integers and roll the header back to v1.
+ let firstPipe = modern.IndexOf('|')
+ let secondPipe = modern.IndexOf('|', firstPipe + 1)
+ let thirdPipe = modern.IndexOf('|', secondPipe + 1)
+ System.IO.File.WriteAllText("p7-legacy.save", ("LV_WORLD_SAVE_V1" + modern.Substring(thirdPipe)))
+ let text = System.IO.File.ReadAllText "p7-legacy.save"
+ Sim.configureBounds 512 384
+ try
+ Assert.IsTrue(text.StartsWith("LV_WORLD_SAVE_V1"), "legacy header must be v1")
+ match WorldSave.loadFromFile "p7-legacy.save" with
+ | Ok loaded ->
+ Assert.AreEqual<int>(64, Sim.mapWidthTiles)
+ Assert.AreEqual<int>(48, Sim.mapHeightTiles)
+ | Error message ->
+ Assert.Fail(sprintf "legacy v1 load failed: %s" message)
+ finally
+ Sim.configureBounds 64 48
+
+ [<TestMethod>]
+ member _.SaveV2RecordsBoundsAndStaysDeterministic () =
+ Sim.configureBounds 512 384
+ try
+ let world = Sim.initialWorld (uint64 7)
+ WorldSave.saveToFile "p7-v2.save" world
+ let text = System.IO.File.ReadAllText "p7-v2.save"
+ Assert.IsTrue(text.StartsWith("LV_WORLD_SAVE_V2"), "v2 save must carry bounds")
+ Sim.configureBounds 64 48
+ match WorldSave.loadFromFile "p7-v2.save" with
+ | Ok loaded ->
+ Assert.AreEqual<int>(512, Sim.mapWidthTiles)
+ Assert.AreEqual<int>(384, Sim.mapHeightTiles)
+ Assert.AreEqual<int64>(loaded.Tick, world.Tick)
+ | Error message ->
+ Assert.Fail(sprintf "v2 load failed: %s" message)
+ finally
+ Sim.configureBounds 64 48
+
+ [<TestMethod>]
member _.ConfiguredLegacyStepCountsRemainExactUntilManualSpeedSelection () =
let control, legacySteps = SimulationControl.initialForConfiguredSteps 7
Assert.AreEqual<int option>(Some 7, legacySteps)