1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 () = WorldBootstrap.initialWorld 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
|