summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Desktop.Tests')
-rw-r--r--src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj1
-rw-r--r--src/LivingVillage.Desktop.Tests/SampleTests.fs60
2 files changed, 61 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj
index 3a9a142..50cb380 100644
--- a/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj
+++ b/src/LivingVillage.Desktop.Tests/LivingVillage.Desktop.Tests.fsproj
@@ -10,6 +10,7 @@
<Compile Include="M6aTests.fs" />
<Compile Include="M6bTests.fs" />
<Compile Include="PrototypeTests.fs" />
+ <Compile Include="SampleTests.fs" />
</ItemGroup>
<ItemGroup>
diff --git a/src/LivingVillage.Desktop.Tests/SampleTests.fs b/src/LivingVillage.Desktop.Tests/SampleTests.fs
new file mode 100644
index 0000000..4c833b5
--- /dev/null
+++ b/src/LivingVillage.Desktop.Tests/SampleTests.fs
@@ -0,0 +1,60 @@
+namespace LivingVillage.Desktop.Tests
+
+open System
+open Microsoft.VisualStudio.TestTools.UnitTesting
+open LivingVillage.Kernel
+open LivingVillage.Kernel.Sim
+open LivingVillage.Desktop
+open LivingVillage.Desktop.VillagePresentation
+
+[<TestClass>]
+type SampleTests () =
+
+ let areEqual (expected: 'T) (actual: 'T) = Assert.AreEqual<'T>(expected, actual)
+
+ let freshWorld () = Sim.initialWorldN 42UL Sim.npcCount
+
+ let freshView (world: World) = M5Interaction.refreshPrompt world M5Interaction.initial
+
+ let driveUntil (maxFrames: int) (stop: SampleScript.SampleState -> bool) =
+ let mutable world = freshWorld ()
+ let mutable view = freshView world
+ let mutable state = SampleScript.initial
+ let mutable frames = 0
+ while frames < maxFrames && not (stop state) do
+ let nextWorld, nextView, nextState = SampleScript.runFrame world view state
+ world <- nextWorld
+ view <- nextView
+ state <- nextState
+ frames <- frames + 1
+ world, view, state, frames
+
+ [<TestMethod>]
+ member _.SampleScriptStartsWalkingTowardHomeDoor () =
+ let spawnWorld = freshWorld ()
+ let movedWorld =
+ List.fold (fun w _ -> Sim.step { Input = { MoveX = -1.0f; MoveY = 0.0f } } w) spawnWorld [ 1..12 ]
+ let view = freshView movedWorld
+ let state, action = SampleScript.step movedWorld view SampleScript.initial
+ areEqual SampleScript.ApproachDoor state.Stage
+ match action with
+ | SampleScript.MoveTo target -> areEqual SampleScript.doorWorldCenter target
+ | other -> Assert.Fail(sprintf "expected MoveTo toward the door, got %A" other)
+
+ [<TestMethod>]
+ member _.SampleScriptEntersTheHomeThroughTheDoor () =
+ let _world, view, state, frames = driveUntil 2400 (fun s -> s.Stage = SampleScript.InspectInterior)
+ Assert.IsTrue(
+ frames < 2400,
+ sprintf "home entry never confirmed; stage=%A frames=%d" state.Stage frames)
+ areEqual (Inside (HomeId 1)) view.HomeMode
+
+ [<TestMethod>]
+ member _.SampleScriptCompletesTheVillageTourWithADialogue () =
+ let _world, view, state, frames =
+ driveUntil 22000 (fun s -> s.Stage = SampleScript.SampleComplete)
+ areEqual SampleScript.SampleComplete state.Stage
+ Assert.IsFalse(state.TimedOut, sprintf "tour timed out; stage=%A frames=%d" state.Stage frames)
+ Assert.IsTrue(state.DialogueTarget.IsSome, "no dialogue was opened during the tour")
+ areEqual Outside view.HomeMode
+ areEqual WorldPanel view.Panel