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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173module Duets.Simulation.Tests.Concerts.Finish
open FsCheck
open FsUnit
open NUnit.Framework
open Test.Common
open Test.Common.Generators
open Duets.Common
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Concerts.Live.Finish
let private attendance = 1000
let private calculateExpectedFanGain fans (modifier: float) =
let totalFans = Queries.Bands.totalFans fans
let fanChange =
float attendance * modifier |> Math.ceilToNearest |> (*) 1<fans>
totalFans + fanChange |> Math.lowerClamp 0<fans>
let private assertFanGain modifier state band concert =
let (Diff(_, updatedFans)) =
finishConcert state concert
|> List.choose (fun effect ->
match effect with
| BandFansChanged(_, diff) -> Some diff
| _ -> None)
|> List.head
let totalFans = Queries.Bands.totalFans updatedFans
totalFans |> should equal (calculateExpectedFanGain band.Fans modifier)
let private venue =
Queries.World.placesByTypeInCity Prague PlaceTypeIndex.ConcertSpace
|> List.find (fun place ->
match place.PlaceType with
| ConcertSpace venue -> venue.Capacity = 800
| _ -> false)
let private concert =
{ Id = Identity.create ()
CityId = Prague
VenueId = venue.Id
Date = Calendar.gameBeginning |> Calendar.Ops.addDays 30<days>
DayMoment = Night
TicketPrice = 20m<dd>
TicketsSold = 0
ParticipationType = Headliner }
let private ongoingConcert =
{ Events = []
Points = 0<quality>
Checklist =
{ MerchStandSetup = false
SoundcheckDone = false }
Concert = concert }
let private simulateAndCheck'
minConcertPoints
maxConcertPoints
participationType
assertFn
=
State.generateN
{ State.defaultOptions with
BandFansMin = 100<fans>
BandFansMax = 1000<fans> }
100
|> List.iter (fun state ->
let band = Queries.Bands.currentBand state
let randomPoints =
Gen.choose (minConcertPoints, maxConcertPoints)
|> Gen.sample 1 1
|> List.head
let concertWithAttendance =
{ concert with
TicketsSold = attendance
ParticipationType = participationType }
let concertWithPoints =
{ ongoingConcert with
Concert = concertWithAttendance
Points = randomPoints * 1<quality> }
assertFn state band concertWithPoints)
let private simulateAndCheck minConcertPoints maxConcertPoints assertFn =
simulateAndCheck' minConcertPoints maxConcertPoints Headliner assertFn
[<Test>]
let ``finishing the concert with less than 40 points should decrease the band fans by 30% of the attendance``
()
=
simulateAndCheck
0
40
(assertFanGain Config.MusicSimulation.concertLowPointFanDecreaseRate)
[<Test>]
let ``finishing the concert with points between 41 and 65 increases the band fame by 0.15``
()
=
simulateAndCheck
41
65
(assertFanGain Config.MusicSimulation.concertMediumPointFanIncreaseRate)
[<Test>]
let ``finishing the concert with points between 66 and 85 increases the band fame by 25% of the attendance``
()
=
simulateAndCheck
66
85
(assertFanGain Config.MusicSimulation.concertGoodPointFanIncreaseRate)
[<Test>]
let ``finishing the concert with more than 85 points increases the band fame by 50% of the attendance``
()
=
simulateAndCheck
86
100
(assertFanGain Config.MusicSimulation.concertHighPointFanIncreaseRate)
[<Test>]
let ``finishing an opening concert only applies 20% of the fan gain`` () =
simulateAndCheck'
86
100
(OpeningAct(dummyHeadlinerBand.Id, 50<percent>))
(assertFanGain 0.1) (* 20% of 50% = 10% *)
[<Test>]
let ``finishing the concert should grant the band the earnings from the tickets sold``
()
=
simulateAndCheck 0 100 (fun state _ concert ->
let moneyEarned =
finishConcert state concert
|> List.choose (fun effect ->
match effect with
| MoneyEarned(_, Incoming(amount, _)) -> Some amount
| _ -> None)
|> List.head
moneyEarned |> should equal 14900m<dd>)
[<Test>]
let ``finishing an opening act concert should grant the band the correct percentage of the tickets sold``
()
=
simulateAndCheck'
0
100
(OpeningAct(dummyHeadlinerBand.Id, 50<percent>))
(fun state _ concert ->
let moneyEarned =
finishConcert state concert
|> List.choose (fun effect ->
match effect with
| MoneyEarned(_, Incoming(amount, _)) -> Some amount
| _ -> None)
|> List.head
moneyEarned |> should equal 7450m<dd>)