Beispiel #1
0
    def calculate_score(self):
        score = 0
        index = 0

        for i in range(10):
            first_roll = self.rolls[index]
            second_roll = self.rolls[index + 1]

            try:
                third_roll = self.rolls[index + 2]
                f = BowlingFrame([first_roll, second_roll, third_roll])
            except IndexError:
                f = BowlingFrame([first_roll, second_roll])

            score += f.calculate_score()
            index += f.calculate_offset()

        return score
Beispiel #2
0
def test_normal_frame():
    f = BowlingFrame([3, 5])
    assert f.calculate_score() == 8, 'got 8 for the frame'
    assert f.calculate_offset() == 2, 'got 2 for offset'
Beispiel #3
0
def test_strike_frame():
    f = BowlingFrame([10, 3, 6])
    assert f.calculate_score() == 19, 'got 19 for the frame'
    assert f.calculate_offset() == 1, 'got 1 for offset'
Beispiel #4
0
def test_spare_frame():
    f = BowlingFrame([6, 4, 8])
    assert f.calculate_score() == 18, 'got 18 for the frame'
    assert f.calculate_offset() == 2, 'got 2 for offset'