summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Kernel.Tests/M6aTests.fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Kernel.Tests/M6aTests.fs')
-rw-r--r--src/LivingVillage.Kernel.Tests/M6aTests.fs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/LivingVillage.Kernel.Tests/M6aTests.fs b/src/LivingVillage.Kernel.Tests/M6aTests.fs
index 7f8d5ea..7184a75 100644
--- a/src/LivingVillage.Kernel.Tests/M6aTests.fs
+++ b/src/LivingVillage.Kernel.Tests/M6aTests.fs
@@ -5,6 +5,7 @@ open System.IO
open Microsoft.VisualStudio.TestTools.UnitTesting
open LivingVillage.Kernel
open LivingVillage.Kernel.Sim
+open LivingVillage.Desktop
module private M6aHarness =
@@ -226,3 +227,68 @@ type M6aTests () =
Assert.AreEqual<int>(0, SimulationControl.stepsPerFrameWithLegacy legacySteps (SimulationControl.togglePause control))
let manuallySelected = SimulationControl.setSpeed TwoX control
Assert.AreEqual<int>(2, SimulationControl.stepsPerFrameWithLegacy None manuallySelected)
+
+ [<TestMethod>]
+ member _.OccupationProfilesMatchTheDesignTable () =
+ let farmer = LivingVillage.Kernel.Occupation.profileOf Occupation.Farmer
+ Assert.AreEqual<int>(60, farmer.InitialMoney)
+ Assert.AreEqual<float32>(100.0f, farmer.InitialEnergy)
+ Assert.AreEqual<int>(12, snd (List.head farmer.InitialInventory))
+ let fisher = Occupation.profileOf Occupation.Fisher
+ Assert.AreEqual<int>(45, fisher.InitialMoney)
+ Assert.AreEqual<float32>(95.0f, fisher.InitialEnergy)
+ Assert.AreEqual<int>(8, snd (List.head fisher.InitialInventory))
+ Assert.AreEqual<int>(3, snd (List.nth fisher.InitialInventory 1))
+ let peddler = Occupation.profileOf Occupation.Peddler
+ Assert.AreEqual<int>(90, peddler.InitialMoney)
+ Assert.AreEqual<int>(6, snd (List.head peddler.InitialInventory))
+ Assert.AreEqual<int>(4, snd (List.nth peddler.InitialInventory 1))
+ let scholar = Occupation.profileOf Occupation.Scholar
+ Assert.AreEqual<int>(70, scholar.InitialMoney)
+ Assert.AreEqual<int>(10, snd (List.head scholar.InitialInventory))
+ Assert.AreEqual<int>(2, snd (List.nth scholar.InitialInventory 1))
+
+ [<TestMethod>]
+ member _.WorldSaveV3RoundTripsOccupation () =
+ let world = Sim.initialWorld (uint64 11)
+ let state = Occupation.stateOf Occupation.Fisher
+ WorldSave.saveToFileWith (Some state) "p10-v3.save" world
+ let text = System.IO.File.ReadAllText "p10-v3.save"
+ Assert.IsTrue(text.StartsWith("LV_WORLD_SAVE_V3"), "v3 header expected")
+ match WorldSave.loadFromFileWith "p10-v3.save" with
+ | Ok (_loaded, restored) ->
+ match restored with
+ | Some st ->
+ Assert.AreEqual<int>(45, st.Profile.InitialMoney)
+ Assert.AreEqual<int>(0, st.TaskToken)
+ Assert.AreEqual<int>(0, st.StoryStage)
+ | None -> Assert.Fail("v3 round trip lost the occupation")
+ | Error message -> Assert.Fail(sprintf "v3 round trip failed: %s" message)
+
+ [<TestMethod>]
+ member _.WorldSaveLegacySavesStillReadWithoutOccupation () =
+ let world = Sim.initialWorld (uint64 42)
+ WorldSave.saveToFile "p10-v2.save" world
+ Assert.IsTrue((System.IO.File.ReadAllText "p10-v2.save").StartsWith("LV_WORLD_SAVE_V2"))
+ match WorldSave.loadFromFileWith "p10-v2.save" with
+ | Ok (_w, occ) -> Assert.AreEqual<obj>(null, occ |> Option.map (fun _ -> box 1) |> Option.defaultValue null)
+ | Error message -> Assert.Fail(sprintf "v2 read failed: %s" message)
+ Sim.configureBounds 64 48
+
+ [<TestMethod>]
+ member _.OccupationBootstrapSavesAreByteIdenticalForSameSeed () =
+ let seed = uint64 4242
+ let state1 = Some (Occupation.stateOf Occupation.Peddler)
+ let state2 = Some (Occupation.stateOf Occupation.Peddler)
+ let world1 = WorldBootstrap.initialWorldWithOccupation false seed 4 state1
+ let world2 = WorldBootstrap.initialWorldWithOccupation false seed 4 state2
+ let text1 = WorldSave.saveWith state1 world1
+ let text2 = WorldSave.saveWith state2 world2
+ Assert.AreEqual<string>(text1, text2)
+
+ [<TestMethod>]
+ member _.OccupationChineseNamesAreKernelSideConstants () =
+ Assert.AreEqual<string>("农夫", Occupation.nameOf Occupation.Farmer)
+ Assert.AreEqual<string>("渔夫", Occupation.nameOf Occupation.Fisher)
+ Assert.AreEqual<string>("货郎", Occupation.nameOf Occupation.Peddler)
+ Assert.AreEqual<string>("书生", Occupation.nameOf Occupation.Scholar)