๐Ÿ“ฆ sleepyfran / duets

๐Ÿ“„ JetLagged.Moodlet.Events.Tests.fs ยท 66 lines
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
66module Duets.Simulation.Tests.Events.Moodlets.JetLagged

open Duets.Data.World
open FsUnit
open NUnit.Framework
open Test.Common

open Duets.Entities
open Duets.Simulation

let private worldMoveEffect prevCity currCity =
    let queryPlace cityId =
        Queries.World.placesByTypeInCity cityId PlaceTypeIndex.Airport
        |> List.head

    let prevCityPlace = queryPlace prevCity
    let currCityPlace = queryPlace currCity


    WorldMoveToPlace(
        Diff(
            (prevCity, prevCityPlace.Id, Ids.Common.lobby),
            (currCity, currCityPlace.Id, Ids.Common.lobby)
        )
    )

[<Test>]
let ``tick of WorldMoveTo does not apply any extra effects if the difference in timezones is less than 4 hours``
    ()
    =
    [ London, Prague; Madrid, Prague; NewYork, LosAngeles ]
    |> List.iter (fun (prevCity, currCity) ->
        Simulation.tickOne dummyState (worldMoveEffect prevCity currCity)
        |> fst
        |> List.filter (function
            | CharacterMoodletsChanged _ -> true
            | _ -> false)
        |> should haveLength 0)

[<Test>]
let ``tick of song finished should apply JetLagged moodlet if the cities are more than 4 timezones apart``
    ()
    =
    [ London, NewYork; NewYork, London; LosAngeles, London; London, LosAngeles ]
    |> List.iter (fun (prevCity, currCity) ->
        let moodletEffect =
            Simulation.tickOne dummyState (worldMoveEffect prevCity currCity)
            |> fst
            |> List.filter (function
                | CharacterMoodletsChanged _ -> true
                | _ -> false)
            |> List.head

        match moodletEffect with
        | CharacterMoodletsChanged(_, Diff(prevMoodlet, currMoodlet)) ->
            prevMoodlet |> should haveCount 0
            currMoodlet |> should haveCount 1

            let moodlet = currMoodlet |> Set.toList |> List.head

            moodlet.MoodletType
            |> should be (ofCase <@ MoodletType.JetLagged @>)

            moodlet.StartedOn |> should equal dummyToday
        | _ -> failwith "Unexpected effect")