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
111
112
113
114
115
116
117
118module Duets.Simulation.Tests.Interactions.Sleep
open FsUnit
open NUnit.Framework
open Test.Common
open Test.Common.Generators
open Duets.Common
open Duets.Data
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Interactions
let bed = fst Items.Furniture.Bed.ikeaBed
let stove = fst Items.Furniture.Stove.lgStove
let state =
let baseState = State.generateOne State.defaultOptions
let currentDate =
Queries.Calendar.today baseState
|> Calendar.Transform.changeDayMoment Morning
let character = Queries.Characters.playableCharacter baseState
State.Calendar.setTime currentDate baseState
|> State.Characters.setAttribute character.Id CharacterAttribute.Energy 40
|> State.Characters.setAttribute character.Id CharacterAttribute.Health 40
let playableCharacter = Queries.Characters.playableCharacter state
[<Test>]
let ``tick of sleep returns the correct time advancement`` () =
let currentDate = Queries.Calendar.today state
Sleep.sleep state currentDate Night
|> Simulation.tickMultiple state
|> fst
|> List.filter (function
| TimeAdvanced _ -> true
| _ -> false)
|> should haveLength 4
[<TestFixture>]
type ``when sleeping less than 3 day moments``() =
let attributeChanges =
Sleep.sleep state dummyToday Midday
|> List.filter (function
| CharacterAttributeChanged _ -> true
| _ -> false)
[<Test>]
member x.``adds 40 points of energy per day moment``() =
attributeChanges
|> List.head
|> should
equal
(CharacterAttributeChanged(
playableCharacter.Id,
CharacterAttribute.Energy,
Diff(40, 80)
))
[<Test>]
member x.``adds 10 points of health per day moment``() =
attributeChanges
|> List.last
|> should
equal
(CharacterAttributeChanged(
playableCharacter.Id,
CharacterAttribute.Health,
Diff(40, 50)
))
[<TestFixture>]
type ``when sleeping more than 3 day moments``() =
let state =
State.Characters.setAttribute
playableCharacter.Id
CharacterAttribute.Energy
0
state
|> State.Characters.setAttribute
playableCharacter.Id
CharacterAttribute.Health
100
let attributeChanges =
Sleep.sleep state dummyToday Night
|> List.filter (function
| CharacterAttributeChanged _ -> true
| _ -> false)
[<Test>]
member x.``adds 20 points of energy per day moment``() =
attributeChanges
|> List.head
|> should
equal
(CharacterAttributeChanged(
playableCharacter.Id,
CharacterAttribute.Energy,
Diff(0, 80)
))
[<Test>]
member x.``reduces 1 point of health per day moment``() =
attributeChanges
|> List.last
|> should
equal
(CharacterAttributeChanged(
playableCharacter.Id,
CharacterAttribute.Health,
Diff(100, 96)
))