-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bowling_game.py
57 lines (45 loc) · 1.39 KB
/
test_bowling_game.py
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
import unittest
import BowlingGame
class TestBowlingGame(unittest.TestCase):
def setUp(self):
self.game = BowlingGame.BowlingGame()
def testGutterGame(self):
for i in range(0, 20):
self.game.roll(0)
assert self.game.score() == 0
def testAllOnes(self):
self.rollMany(1, 20)
assert self.game.score() == 20
def testOneSpare(self):
self.game.roll(5)
self.game.roll(5)
self.game.roll(3)
self.rollMany(0, 17)
assert self.game.score() == 16
def testOneStrike(self):
self.game.roll(10)
self.game.roll(4)
self.game.roll(3)
self.rollMany(0, 18) # should be 18
assert self.game.score() == 24
def testPerfectGame(self):
self.rollMany(10, 12)
assert self.game.score() == 300
def testAllSpare(self):
self.rollMany(5, 21) # should be 20
assert self.game.score() == 150
def testMixedGame(self):
self.game.roll(5)
self.game.roll(5)
self.game.roll(10)
self.game.roll(10)
self.game.roll(0)
self.game.roll(3)
self.rollMany(1, 16)
assert self.game.score() == 68
def testNegatifValue(self):
with self.assertRaises(ValueError):
self.game.roll(-5)
def rollMany(self, pins, rolls):
for i in range(rolls):
self.game.roll(pins)