Skip to content

Commit e0ea43e

Browse files
ricemeryabo64
authored andcommitted
Update to scala 2.12.1. And, simplify test suite. Refs #235 (#250)
1 parent 5f05686 commit e0ea43e

File tree

2 files changed

+28
-106
lines changed

2 files changed

+28
-106
lines changed

exercises/bowling/build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
scalaVersion := "2.11.7"
1+
scalaVersion := "2.12.1"
22

3-
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.5" % "test"
3+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"

exercises/bowling/src/test/scala/BowlingSuite.scala

Lines changed: 26 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -4,234 +4,156 @@ class BowlingSuite extends FunSuite with Matchers {
44
// returns the final score of a bowling game
55
test("should be able to score a game with all zeros") {
66
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))
118
}
129

1310
test("should be able to score a game with no strikes or spares") {
1411
pending
1512
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))
2014
}
2115

2216
test("a spare followed by zeros is worth ten points") {
2317
pending
2418
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))
2920
}
3021

3122
test("points scored in the roll after a spare are counted twice") {
3223
pending
3324
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))
3826
}
3927

4028
test("consecutive spares each get a one roll bonus") {
4129
pending
4230
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))
4732
}
4833

4934
test("a spare in the last frame gets a one roll bonus that is counted once") {
5035
pending
5136
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))
5638
}
5739

5840
test("a strike earns ten points in a frame with a single roll") {
5941
pending
6042
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))
6544
}
6645

6746
test("points scored in the two rolls after a strike are counted twice as a bonus") {
6847
pending
6948
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))
7450
}
7551

7652
test("consecutive strikes each get the two roll bonus") {
7753
pending
7854
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))
8356
}
8457

8558
test("a strike in the last frame gets a two roll bonus that is counted once") {
8659
pending
8760
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))
9262
}
9363

9464
test("rolling a spare with the two roll bonus does not get a bonus roll") {
9565
pending
9666
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))
10168
}
10269

10370
test("strikes with the two roll bonus do not get bonus rolls") {
10471
pending
10572
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))
11074
}
11175

11276
test("a strike with the one roll bonus after a spare in the last frame does not get a bonus") {
11377
pending
11478
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))
11980
}
12081

12182
test("all strikes is a perfect game") {
12283
pending
12384
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))
12886
}
12987

13088
test("rolls can not score negative points") {
13189
pending
13290
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)
13792
}
13893

13994
test("a roll can not score more than 10 points") {
14095
pending
14196
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)
14698
}
14799

148100
test("two rolls in a frame can not score more than 10 points") {
149101
pending
150102
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)
155104
}
156105

157106
test("two bonus rolls after a strike in the last frame can not score more than 10 points") {
158107
pending
159108
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)
164110
}
165111

166112
test("two bonus rolls after a strike in the last frame can score more than 10 points if one is a strike") {
167113
pending
168114
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))
173116
}
174117

175118
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") {
176119
pending
177120
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)
182122
}
183123

184124
test("an unstarted game can not be scored") {
185125
pending
186126
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)
191128
}
192129

193130
test("an incomplete game can not be scored") {
194131
pending
195132
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)
200134
}
201135

202136
test("a game with more than ten frames can not be scored") {
203137
pending
204138
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)
209140
}
210141

211142
test("bonus rolls for a strike in the last frame must be rolled before score can be calculated") {
212143
pending
213144
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)
218146
}
219147

220148
test("both bonus rolls for a strike in the last frame must be rolled before score can be calculated") {
221149
pending
222150
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)
227152
}
228153

229154
test("bonus roll for a spare in the last frame must be rolled before score can be calculated") {
230155
pending
231156
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)
236158
}
237159
}

0 commit comments

Comments
 (0)