@@ -4,234 +4,156 @@ class BowlingSuite extends FunSuite with Matchers {
4
4
// returns the final score of a bowling game
5
5
test(" should be able to score a game with all zeros" ) {
6
6
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
7
- score match {
8
- case Right (n) => assert(n == 0 )
9
- case Left (_) => fail(" should be able to score a game with all zeros" )
10
- }
7
+ score should be (Right (0 ))
11
8
}
12
9
13
10
test(" should be able to score a game with no strikes or spares" ) {
14
11
pending
15
12
val score = List (3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
16
- score match {
17
- case Right (n) => assert(n == 90 )
18
- case Left (_) => fail(" should be able to score a game with no strikes or spares" )
19
- }
13
+ score should be (Right (90 ))
20
14
}
21
15
22
16
test(" a spare followed by zeros is worth ten points" ) {
23
17
pending
24
18
val score = List (6 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
25
- score match {
26
- case Right (n) => assert(n == 10 )
27
- case Left (_) => fail(" a spare followed by zeros is worth ten points" )
28
- }
19
+ score should be (Right (10 ))
29
20
}
30
21
31
22
test(" points scored in the roll after a spare are counted twice" ) {
32
23
pending
33
24
val score = List (6 , 4 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
34
- score match {
35
- case Right (n) => assert(n == 16 )
36
- case Left (_) => fail(" points scored in the roll after a spare are counted twice" )
37
- }
25
+ score should be (Right (16 ))
38
26
}
39
27
40
28
test(" consecutive spares each get a one roll bonus" ) {
41
29
pending
42
30
val score = List (5 , 5 , 3 , 7 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
43
- score match {
44
- case Right (n) => assert(n == 31 )
45
- case Left (_) => fail(" consecutive spares each get a one roll bonus" )
46
- }
31
+ score should be (Right (31 ))
47
32
}
48
33
49
34
test(" a spare in the last frame gets a one roll bonus that is counted once" ) {
50
35
pending
51
36
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 , 7 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
52
- score match {
53
- case Right (n) => assert(n == 17 )
54
- case Left (_) => fail(" a spare in the last frame gets a one roll bonus that is counted once" )
55
- }
37
+ score should be (Right (17 ))
56
38
}
57
39
58
40
test(" a strike earns ten points in a frame with a single roll" ) {
59
41
pending
60
42
val score = List (10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
61
- score match {
62
- case Right (n) => assert(n == 10 )
63
- case Left (_) => fail(" a strike earns ten points in a frame with a single roll" )
64
- }
43
+ score should be (Right (10 ))
65
44
}
66
45
67
46
test(" points scored in the two rolls after a strike are counted twice as a bonus" ) {
68
47
pending
69
48
val score = List (10 , 5 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
70
- score match {
71
- case Right (n) => assert(n == 26 )
72
- case Left (_) => fail(" points scored in the two rolls after a strike are counted twice as a bonus" )
73
- }
49
+ score should be (Right (26 ))
74
50
}
75
51
76
52
test(" consecutive strikes each get the two roll bonus" ) {
77
53
pending
78
54
val score = List (10 , 10 , 10 , 5 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
79
- score match {
80
- case Right (n) => assert(n == 81 )
81
- case Left (_) => fail(" consecutive strikes each get the two roll bonus" )
82
- }
55
+ score should be (Right (81 ))
83
56
}
84
57
85
58
test(" a strike in the last frame gets a two roll bonus that is counted once" ) {
86
59
pending
87
60
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 7 , 1 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
88
- score match {
89
- case Right (n) => assert(n == 18 )
90
- case Left (_) => fail(" a strike in the last frame gets a two roll bonus that is counted once" )
91
- }
61
+ score should be (Right (18 ))
92
62
}
93
63
94
64
test(" rolling a spare with the two roll bonus does not get a bonus roll" ) {
95
65
pending
96
66
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 7 , 3 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
97
- score match {
98
- case Right (n) => assert(n == 20 )
99
- case Left (_) => fail(" rolling a spare with the two roll bonus does not get a bonus roll" )
100
- }
67
+ score should be (Right (20 ))
101
68
}
102
69
103
70
test(" strikes with the two roll bonus do not get bonus rolls" ) {
104
71
pending
105
72
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 , 10 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
106
- score match {
107
- case Right (n) => assert(n == 30 )
108
- case Left (_) => fail(" strikes with the two roll bonus do not get bonus rolls" )
109
- }
73
+ score should be (Right (30 ))
110
74
}
111
75
112
76
test(" a strike with the one roll bonus after a spare in the last frame does not get a bonus" ) {
113
77
pending
114
78
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 , 10 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
115
- score match {
116
- case Right (n) => assert(n == 20 )
117
- case Left (_) => fail(" a strike with the one roll bonus after a spare in the last frame does not get a bonus" )
118
- }
79
+ score should be (Right (20 ))
119
80
}
120
81
121
82
test(" all strikes is a perfect game" ) {
122
83
pending
123
84
val score = List (10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
124
- score match {
125
- case Right (n) => assert(n == 300 )
126
- case Left (_) => fail(" all strikes is a perfect game" )
127
- }
85
+ score should be (Right (300 ))
128
86
}
129
87
130
88
test(" rolls can not score negative points" ) {
131
89
pending
132
90
val score = List (- 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
133
- score match {
134
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
135
- case Left (_) =>
136
- }
91
+ score.isLeft should be (true )
137
92
}
138
93
139
94
test(" a roll can not score more than 10 points" ) {
140
95
pending
141
96
val score = List (11 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
142
- score match {
143
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
144
- case Left (_) =>
145
- }
97
+ score.isLeft should be (true )
146
98
}
147
99
148
100
test(" two rolls in a frame can not score more than 10 points" ) {
149
101
pending
150
102
val score = List (5 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
151
- score match {
152
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
153
- case Left (_) =>
154
- }
103
+ score.isLeft should be (true )
155
104
}
156
105
157
106
test(" two bonus rolls after a strike in the last frame can not score more than 10 points" ) {
158
107
pending
159
108
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 5 , 6 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
160
- score match {
161
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
162
- case Left (_) =>
163
- }
109
+ score.isLeft should be (true )
164
110
}
165
111
166
112
test(" two bonus rolls after a strike in the last frame can score more than 10 points if one is a strike" ) {
167
113
pending
168
114
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 , 6 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
169
- score match {
170
- case Right (n) => assert(n == 26 )
171
- case Left (_) => fail(" two bonus rolls after a strike in the last frame can score more than 10 points if one is a strike" )
172
- }
115
+ score should be (Right (26 ))
173
116
}
174
117
175
118
test(" the second bonus rolls after a strike in the last frame can not be a strike if the first one is not a strike" ) {
176
119
pending
177
120
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 6 , 10 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
178
- score match {
179
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
180
- case Left (_) =>
181
- }
121
+ score.isLeft should be (true )
182
122
}
183
123
184
124
test(" an unstarted game can not be scored" ) {
185
125
pending
186
126
val score = List ().foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
187
- score match {
188
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
189
- case Left (_) =>
190
- }
127
+ score.isLeft should be (true )
191
128
}
192
129
193
130
test(" an incomplete game can not be scored" ) {
194
131
pending
195
132
val score = List (0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
196
- score match {
197
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
198
- case Left (_) =>
199
- }
133
+ score.isLeft should be (true )
200
134
}
201
135
202
136
test(" a game with more than ten frames can not be scored" ) {
203
137
pending
204
138
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
205
- score match {
206
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
207
- case Left (_) =>
208
- }
139
+ score.isLeft should be (true )
209
140
}
210
141
211
142
test(" bonus rolls for a strike in the last frame must be rolled before score can be calculated" ) {
212
143
pending
213
144
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
214
- score match {
215
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
216
- case Left (_) =>
217
- }
145
+ score.isLeft should be (true )
218
146
}
219
147
220
148
test(" both bonus rolls for a strike in the last frame must be rolled before score can be calculated" ) {
221
149
pending
222
150
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
223
- score match {
224
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
225
- case Left (_) =>
226
- }
151
+ score.isLeft should be (true )
227
152
}
228
153
229
154
test(" bonus roll for a spare in the last frame must be rolled before score can be calculated" ) {
230
155
pending
231
156
val score = List (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 ).foldLeft(Bowling ())((acc, roll) => acc.roll(roll)).score()
232
- score match {
233
- case Right (_) => fail(" Unexpected score returned. Failure expected" )
234
- case Left (_) =>
235
- }
157
+ score.isLeft should be (true )
236
158
}
237
159
}
0 commit comments