-
Notifications
You must be signed in to change notification settings - Fork 0
/
bowling_tests.py
44 lines (34 loc) · 1.12 KB
/
bowling_tests.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
import unittest
from bowling import Game
import unittest
class PythonBowlingGame(unittest.TestCase):
# initialise game in setup, exit in tear town
def setUp(self):
self.game = Game(1)
def test_gutter_game(self):
self.roll_many(20, 0)
self.assertEqual(0, self.game.score()[0])
def test_all_ones(self):
self.roll_many(20, 1)
self.assertEqual(20, self.game.score()[0])
def test_one_spare(self):
self.game.roll(5)
self.game.roll(5)
self.game.roll(3)
self.roll_many(17,0)
self.assertEqual(16, self.game.score()[0])
def test_one_strike(self):
self.game.roll(10)
self.game.roll(3)
self.game.roll(4)
self.roll_many(16, 0)
self.assertEqual(24, self.game.score()[0])
def test_perfect_game(self):
self.roll_many(12,10)
self.assertEqual(300, self.game.score()[0])
# may also be worth testing that the maximum number of rolls on last turn is 3
def roll_many(self, n, pins):
for i in range(n):
self.game.roll(pins)
if __name__ == '__main__':
unittest.main()