๐Ÿ“ฆ sleepyfran / duets

๐Ÿ“„ WeatherTransition.Tests.fs ยท 111 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111module Duets.Simulation.Tests.Weather.Transition

open Test.Common
open Test.Common.Generators
open NUnit.Framework
open FsUnit

open Aether
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Weather.Transition

let private staticDoubleRandom value =
    { new System.Random() with
        override this.NextDouble() = value }
    |> RandomGen.change

    new RandomGenDisposable()

let createStateWith cityId weather season =
    let home =
        Queries.World.placesByTypeInCity cityId PlaceTypeIndex.Home |> List.head

    State.generateOne State.defaultOptions
    |> Optic.set Lenses.State.currentPosition_ (cityId, home.Id, "")
    |> Optic.set (Lenses.FromState.Weather.forCity_ cityId) weather
    |> Optic.set
        Lenses.State.today_
        { Season = season
          Day = 1<days>
          Year = 2025<years>
          DayMoment = EarlyMorning }

[<Test>]
let ``Los Angeles - Sunny to Cloudy transition`` () =
    use _ = staticDoubleRandom 0.95

    let state = createStateWith LosAngeles WeatherCondition.Sunny Summer

    let effects = dailyWeatherUpdate state

    effects
    |> should
        contain
        (WeatherChanged(
            LosAngeles,
            Diff(WeatherCondition.Sunny, WeatherCondition.Cloudy)
        ))

[<Test>]
let ``Madrid - Stormy to Cloudy in winter`` () =
    use _ = staticDoubleRandom 0.4

    let state = createStateWith Madrid WeatherCondition.Stormy Winter

    let effects = dailyWeatherUpdate state

    effects
    |> should
        contain
        (WeatherChanged(
            Madrid,
            Diff(WeatherCondition.Stormy, WeatherCondition.Cloudy)
        ))

[<Test>]
let ``London - Rainy stays Rainy in autumn`` () =
    use _ = staticDoubleRandom 0.5

    let state = createStateWith London WeatherCondition.Rainy Autumn

    let effects = dailyWeatherUpdate state

    effects
    |> List.filter (function
        | WeatherChanged(cityId, _) -> cityId = London
        | _ -> false)
    |> should haveLength 0

[<Test>]
let ``Prague - Sunny to Snowy in winter`` () =
    use _ = staticDoubleRandom 0.7

    let state = createStateWith Prague WeatherCondition.Sunny Winter

    let effects = dailyWeatherUpdate state

    effects
    |> should
        contain
        (WeatherChanged(
            Prague,
            Diff(WeatherCondition.Sunny, WeatherCondition.Snowy)
        ))

[<Test>]
let ``New York - Rainy to Stormy in spring`` () =
    use _ = staticDoubleRandom 0.7

    let state = createStateWith NewYork WeatherCondition.Rainy Spring

    let effects = dailyWeatherUpdate state

    effects
    |> should
        contain
        (WeatherChanged(
            NewYork,
            Diff(WeatherCondition.Rainy, WeatherCondition.Stormy)
        ))