Exemple #1
0
def main():
	game = BowlingGame([1, 4, 4, 5, 6, 3, 5, 1, 1, 0, 1, 7, 3, 6, 4, 3, 2, 1, 6, 2])	# 20
	print(game.result()) # 65

	game = BowlingGame([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] )	# 20
	print(game.result()) # 0

	game = BowlingGame([10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10])	# 12
	print(game.result()) # 300

	game = BowlingGame([5, 1, 1, 0, 1, 7, 3, 6, 4, 3, 2, 1, 6])		# 13
	print(game.result()) # invalid number of frames	
    def test_bowling_game_result_calculates_the_score_of_the_game_correctly(
            self):
        test_game1 = BowlingGame(
            [1, 4, 4, 5, 6, 3, 5, 1, 1, 0, 1, 7, 3, 6, 4, 3, 2, 1, 6, 2])
        test_game2 = BowlingGame(
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        test_game3 = BowlingGame(
            [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10])
        test_game4 = BowlingGame([5, 1, 1, 0, 1, 7, 3, 6, 4, 3, 2, 1, 6])

        self.assertEqual(test_game1.result(), '65')
        self.assertEqual(test_game2.result(), '0')
        self.assertEqual(test_game3.result(), '300')
        self.assertEqual(test_game4.result(), 'Invalid number of frames.')
    def test_result_if_there_are_many_strikes(self):
        game = BowlingGame(
            [1, 4, 10, 1, 2, 10, 1, 1, 1, 0, 10, 1, 2, 1, 1, 1, 1])

        res = game.result()

        self.assertEqual(res, 56)
    def test_result_if_there_is_one_strike(self):
        game = BowlingGame(
            [1, 4, 10, 1, 2, 3, 5, 1, 1, 0, 1, 2, 3, 1, 4, 3, 2, 1, 6])

        res = game.result()

        self.assertEqual(res, 54)
    def test_result_if_there_are_no_strikes_and_spares(self):
        game = BowlingGame(
            [1, 4, 4, 5, 6, 3, 5, 1, 1, 0, 1, 7, 3, 6, 4, 3, 2, 1, 6, 2])

        res = game.result()

        self.assertEqual(res, 65)
    def test_result_if_there_is_a_spare_in_the_tenth_frame(self):
        game = BowlingGame(
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 1])

        res = game.result()

        self.assertEqual(res, 29)
    def test_result_if_there_are_many_stpares_in_a_row(self):
        game = BowlingGame(
            [6, 4, 3, 7, 3, 0, 5, 5, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

        res = game.result()

        self.assertEqual(res, 42)
    def test_result_if_there_is_one_stpare(self):
        game = BowlingGame(
            [1, 4, 1, 2, 5, 5, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

        res = game.result()

        self.assertEqual(res, 21)
    def test_result_if_there_are_only_strikes_in_a_row(self):
        game = BowlingGame([10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10])

        res = game.result()

        self.assertEqual(res, 300)
Exemple #10
0
    def test_BowlingGame_result_calculates_correctly_spares_only(self):
        game = BowlingGame([3, 7, 6, 4, 2, 8, 9, 1, 1, 9, 5, 5, 4, 6, 2, 8, 9, 1, 3, 7, 5])
        game.play()

        self.assertEqual(game.result(), 146)
Exemple #11
0
    def test_BowlingGame_result_calculates_correctly_open_frames_only(self):
        game = BowlingGame([1, 4, 4, 5, 6, 3, 5, 1, 1, 0, 1, 7, 3, 6, 4, 3, 2, 1, 6, 2])
        game.play()

        self.assertEqual(game.result(), 65)
Exemple #12
0
    def test_BowlingGame_result_calculates_correctly_strikes_only(self):
        game = BowlingGame([10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10])
        game.play()

        self.assertEqual(game.result(), 300)