summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests/DesktopTests.fs
blob: 650f7570786cc1810dae028b9fceb639e0cf6fd9 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
namespace LivingVillage.Desktop.Tests

open Microsoft.VisualStudio.TestTools.UnitTesting
open LivingVillage.Kernel
open LivingVillage.Kernel.Sim
open LivingVillage.Desktop

module private Harness =

    let atNpc (id: int) (world: World) : World =
        let npc = world.Npcs.[id]
        { world with Avatar = { world.Avatar with Pos = npc.Pos } }

[<TestClass>]
type DesktopTests () =

    [<TestMethod>]
    member _.InteractOpensTheSixIntentMenu () =
        let world = Sim.initialWorldN 42UL 4 |> Harness.atNpc 0
        let next, view = M5Interaction.apply Interact world M5Interaction.initial

        Assert.AreEqual<World>(world, next)
        Assert.AreEqual<M5Panel>(DialoguePanel, view.Panel)
        Assert.AreEqual<int>(6, view.Menu.Value.Options.Length)
        Assert.IsTrue(M5Interaction.titleText view |> fun text -> text.Contains("SMALLTALK"))

    [<TestMethod>]
    member _.SelectingAnIntentUpdatesWorldAndChronicle () =
        let world = Sim.initialWorldN 42UL 4 |> Harness.atNpc 0
        let openedWorld, opened = M5Interaction.apply Interact world M5Interaction.initial
        let next, view = M5Interaction.apply Intent1 openedWorld opened

        Assert.IsTrue(next.Events |> List.exists (fun event ->
            match event.Kind with
            | DialogueEvent _ -> true
            | _ -> false))
        Assert.IsTrue(next.Annals |> List.exists (fun entry ->
            match entry.Kind with
            | DialogueAnnal _ -> true
            | _ -> false))
        Assert.IsTrue(view.Chronicle.Contains("dialogue"))
        Assert.IsTrue(view.Status.Contains("dialogue"))

    [<TestMethod>]
    member _.NeedsAndObservationPanelsUseKernelViews () =
        let world = Sim.initialWorldN 42UL 4 |> Harness.atNpc 0
        let afterStep = Sim.step { Input = { MoveX = 0.0f; MoveY = 0.0f } } world
        let _, needsView = M5Interaction.apply ToggleNeeds afterStep M5Interaction.initial
        let _, observationView = M5Interaction.apply Observe world M5Interaction.initial

        Assert.AreEqual<Needs>(afterStep.Avatar.Mind.Needs, needsView.Needs.Value.Needs)
        Assert.IsTrue(observationView.Observations |> List.exists (fun observation -> observation.Id = NpcId 0))

    [<TestMethod>]
    member _.HeadlessSmokeProvesTheThreeHopCausalChain () =
        let result = Program.M5Smoke.run ()

        Assert.IsTrue(result.Passed, result.Failure)
        Assert.AreEqual<int>(6, result.MenuOptions)
        Assert.AreEqual<int>(4, result.RumorPathLength)
        Assert.IsTrue(result.Chronicle.Contains("dialogue"))
        Assert.IsTrue(result.RumorTrace.Contains("receiver=-1"))
        Assert.IsTrue(result.RumorTrace.Contains("depth=3"))

    [<TestMethod>]
    member _.DayNightStateChangesTheRenderProfile () =
        let day = M6Presentation.profileAtTick (6L * Sim.ticksPerDay / 24L)
        let night = M6Presentation.profileAtTick (22L * Sim.ticksPerDay / 24L)

        Assert.AreEqual<M6DayNight>(Day, day.Mode)
        Assert.AreEqual<M6DayNight>(Night, night.Mode)
        Assert.AreNotEqual(day.Background, night.Background)
        Assert.AreNotEqual(day.WorldTint, night.WorldTint)