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
118
119
120
121
122
123
124
125
126
127
128module Duets.Simulation.Tests.Events.Career
#nowarn "25"
open Duets.Data.World
open FsUnit
open NUnit.Framework
open Test.Common
open Duets.Data
open Duets.Entities
open Duets.Simulation
let baristaJob =
{ Id = Barista
CurrentStage = Careers.BaristaCareer.stages |> List.head
Location = dummyCity.Id, dummyPlace.Id, Ids.Common.cafe }
let bartenderJob =
{ Id = Bartender
CurrentStage = Careers.BartenderCareer.stages |> List.head
Location = dummyCity.Id, dummyPlace.Id, Ids.Common.cafe }
let baristaSkill = Skill.create SkillId.Barista
let bartendingSkill = Skill.create SkillId.Bartending
let shiftPerformedEffect job =
CareerShiftPerformed(job, 2<dayMoments>, 100m<dd>)
(* --------- Skill improvement. --------- *)
[<Test>]
let ``tick of CareerShiftPerformed should improve career skill if chance of 25% succeeds``
()
=
[ 1..25 ]
|> List.iter (fun randomValue ->
use _ = changeToStaticRandom randomValue
Simulation.tickOne dummyState (shiftPerformedEffect baristaJob)
|> fst
|> List.filter (function
| SkillImproved _ -> true
| _ -> false)
|> should haveLength 1)
[<Test>]
let ``tick of CareerShiftPerformed does not improve career skill if chance of 25% fails``
()
=
[ 26..100 ]
|> List.iter (fun randomValue ->
use _ = changeToStaticRandom randomValue
Simulation.tickOne dummyState (shiftPerformedEffect baristaJob)
|> fst
|> List.filter (function
| SkillImproved _ -> true
| _ -> false)
|> should haveLength 0)
[<Test>]
let ``tick of CareerShiftPerformed with successful chance improves job career by 1``
()
=
use _ = changeToStaticRandom 5
[ baristaJob, baristaSkill; bartenderJob, bartendingSkill ]
|> List.iter (fun (job, expectedSkill) ->
Simulation.tickOne dummyState (shiftPerformedEffect job)
|> fst
|> List.filter (function
| SkillImproved _ -> true
| _ -> false)
|> List.head
|> fun (SkillImproved(_, diff)) ->
diff |> should equal (Diff((expectedSkill, 0), (expectedSkill, 1))))
(* --------- Promotions --------- *)
let private promotionEffects =
function
| CareerPromoted _ -> true
| _ -> false
[<Test>]
let ``tick of CareerShiftPerformed does not grant promotion if 10% chance fails``
()
=
[ 10..100 ]
|> List.iter (fun randomValue ->
use _ = changeToStaticRandom randomValue
Simulation.tickOne dummyState (shiftPerformedEffect baristaJob)
|> fst
|> List.filter promotionEffects
|> should haveLength 0)
[<Test>]
let ``tick of CareerShiftPerformed does not grant promotion if character does not have enough skills for next stage even if 10% chance succeeds``
()
=
[ 0..9 ]
|> List.iter (fun randomValue ->
use _ = changeToStaticRandom randomValue
Simulation.tickOne dummyState (shiftPerformedEffect baristaJob)
|> fst
|> List.filter promotionEffects
|> should haveLength 0)
[<Test>]
let ``tick of CareerShiftPerformed grants promotion if character has enough skills for next stage and 10% chance succeeds``
()
=
let stateWithSkill =
dummyState
|> State.Skills.add dummyCharacter.Id (Skill.create SkillId.Barista, 20)
[ 0..9 ]
|> List.iter (fun randomValue ->
use _ = changeToStaticRandom randomValue
Simulation.tickOne stateWithSkill (shiftPerformedEffect baristaJob)
|> fst
|> List.filter promotionEffects
|> should haveLength 1)