-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bowling.py
60 lines (34 loc) · 1.11 KB
/
test_bowling.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
58
59
60
import unittest
from bowling import BowlingGame
class TestBowlingGame(unittest.TestCase):
def setUp(self):
self.game = BowlingGame()
def test_gutter_game(self):
self.roll_many(0, 20)
self.assertEqual(self.game.score(), 0)
def test_all_ones(self):
self.roll_many(1, 20)
self.assertEqual(self.game.score(), 20)
def test_one_spare(self):
self.game.roll(5)
self.game.roll(5)
self.game.roll(3)
self.roll_many(0, 17)
self.assertEqual(self.game.score(), 16)
def test_one_strike(self):
self.game.roll(10)
self.game.roll(4)
self.game.roll(3)
self.roll_many(0, 16)
self.assertEqual(self.game.score(), 16)
def test_perfect_game(self):
self.roll_many(10, 12)
self.assertEqual(self.game.score(), 300)
def test_all_spares(self):
self.roll_many(5, 21)
self.assertEqual(self.game.score(), 150)
def roll_many(self, pins, rolls):
for i in range(rolls):
self.game.roll(pins)
if __name__ == "__main__":
unittest.main()