def test_normal_scoring_other_score(self): ''' Test normal score (no spares or strikes) but with other scoreboard ''' frames = [Frame(1, 2)] * 9 + [Frame(1, 5)] self._assert_score_equals(frames, 33)
def test_a_strike_is_not_a_spare(self): ''' Strike = True != Spare == True ''' frame = Frame(10, 0) self.assertTrue(frame.is_strike()) self.assertFalse(frame.is_spare())
def test_last_frame_strike_spare(self): ''' Second last frame has a strike ''' frames = [Frame(0, 0)] * 8 + [Frame(10, 0)] frames += [FinalFrame(7, 3, 3)] self._assert_score_equals(frames, 33)
def test_a_frame_knows_if_next(self): ''' A LinkedFrame can check for next frame ''' next_frame = Frame(10, 0) current_frame = Frame(4, 4) current_frame_linked = LinkedFrame(current_frame, next_frame) self.assertTrue(current_frame_linked.has_next_frame())
def test_a_frame_knows_next_frame(self): ''' A LinkedFrame knows about next frame ''' next_frame = Frame(10, 0) current_frame = Frame(4, 4) current_frame_linked = LinkedFrame(current_frame, next_frame) self.assertIs(current_frame_linked.next_frame, next_frame)
def test_two_different_frames(self): ''' Two different frames shouldn't be equal ''' frame = Frame(10, 0) other_frame = Frame(10, 0) self.assertTrue(frame == other_frame) self.assertFalse(frame != other_frame)
def test_spare_scoring(self): ''' Now add an spare into the mix. Spares are when two hits from the same frame add up to 10 pins. This has a bonus score equal to the next roll ''' frames = [Frame(8, 2)] + [Frame(5, 2)] + [Frame(0, 0)] * 8 self._assert_score_equals(frames, 22)
def build_frame(self, frame_input): ''' Builds a single frame ''' if frame_input == "X-": return Frame(10, 0) else: return Frame(int(frame_input[0]), int(frame_input[1]))
def test_mix_spares_and_strikes(self): ''' Mix spares and strikes ''' frames = [Frame(10, 0)] + [Frame(5, 5)] + [Frame(5, 5)] frames += [Frame(10, 0)] + [Frame(10, 0)] + [Frame(5, 5)] frames += [Frame(5, 0)] + [Frame(0, 0)] * 3 self._assert_score_equals(frames, 20 + 15 + 20 + 25 + 20 + 15 + 5)
def test_full_game_into_frames(self): ''' Pass a full normal game and check it's correctly converted into frames ''' game_string = "00102030405060708090" expected_frames = [Frame(0, 0)] + [Frame(1, 0)] + [Frame(2, 0)] expected_frames += [Frame(3, 0)] + [Frame(4, 0)] + [Frame(5, 0)] expected_frames += [Frame(6, 0)] + [Frame(7, 0)] + [Frame(8, 0)] expected_frames += [FinalFrame(9, 0, 0)] factory = FrameFactory() self.assertEqual(factory.build_game(game_string), expected_frames)
def test_a_frame_knows_if_not_next(self): ''' A LinkedFrame also knows if it doesn't have a next frame ''' current_frame = Frame(4, 4) current_frame_linked = LinkedFrame(current_frame) self.assertFalse(current_frame_linked.has_next_frame())
def test_final_frame_equals(self): ''' A FinalFrame is not a Frame! ''' frame = Frame(10, 0) final_frame = FinalFrame(10, 0, 0) self.assertFalse(frame == final_frame)
def test_convert_strike(self): ''' Convert a strike "X-" ''' frame_to_convert = "X-" converted_frame = Frame(10, 0) self._assert_conversion_is_correct(converted_frame, frame_to_convert)
def test_convert_other_frame(self): ''' Convert a normal frame string, but with other score ''' frame_to_convert = "41" converted_frame = Frame(4, 1) self._assert_conversion_is_correct(converted_frame, frame_to_convert)
def test_convert_normal_frames(self): ''' Convert a normal frame string, without the extra bonus ''' frame_to_convert = "12" converted_frame = Frame(1, 2) self._assert_conversion_is_correct(converted_frame, frame_to_convert)
def test_normal_scoring(self): ''' Test that normal scores (no spares or strikes) are added normally ''' frames = [Frame(1, 2)] * 10 self._assert_score_equals(frames, 30)
def test_a_frame_isnt_other_object(self): ''' If not a Frame, shouldn't be equals ''' frame = Frame(10, 0) other = 'other' self.assertFalse(frame == other) self.assertTrue(frame != other)
def test_builds_frame_references(self): ''' Check the builder is able to correctly transform a list of frames to linked frames ''' frames = [] for index in range(0, 9): frames += [Frame(index, 0)] frames += [FinalFrame(1, 2, 3)] first_linked_frame = self._ready_linked_frame_list(frames) builder = FrameListBuilder(frames) built_frame = builder.build() next_frame = built_frame next_expected_frame = first_linked_frame while next_frame.has_next_frame(): self.assertEquals(next_expected_frame, next_frame) next_frame = next_frame.next_frame next_expected_frame = next_expected_frame.next_frame
def test_final_frame_strike(self): ''' Test the final frame strikes act as expected ''' frames = [Frame(0, 0)] * 9 + [FinalFrame(10, 1, 1)] self._assert_score_equals(frames, 12)
def test_adds_rolls_correctly(self): ''' The rolls are added correctly ''' frame = Frame(4, 1) self.assertEqual(frame.total_frame_score(), 5)
def test_final_frame_spare(self): ''' Test the final frame acts as expected ''' frames = [Frame(0, 0)] * 9 + [FinalFrame(5, 5, 3)] self._assert_score_equals(frames, 13)
def test_detects_a_spare_correctly(self): ''' Detects a spare ''' frame = Frame(5, 5) self.assertTrue(frame.is_spare())
def test_several_strikes_scoring(self): ''' Roll several strikes, see what happens ''' frames = [Frame(10, 0)] * 4 + [Frame(0, 0)] * 6 self._assert_score_equals(frames, 30 + 30 + 20 + 10)
def test_several_spares_scoring(self): ''' Roll several spares, see what happens ''' frames = [Frame(8, 2)] * 4 + [Frame(0, 0)] * 6 self._assert_score_equals(frames, 18 + 18 + 18 + 10)
def test_strike_scoring(self): ''' Roll a strike, should count the next frame as bonus ''' frames = [Frame(10, 0)] + [Frame(5, 2)] + [Frame(0, 0)] * 8 self._assert_score_equals(frames, 24)
def test_detects_a_strike_correctly(self): ''' Detects a strike ''' frame = Frame(10, 0) self.assertTrue(frame.is_strike())
def test_total_maximum_score(self): ''' The 300! ''' frames = [Frame(10, 0)] * 9 + [FinalFrame(10, 10, 10)] self._assert_score_equals(frames, 300)
def test_final_frame_spare_strike(self): ''' Spare + strike on the final frame ''' frames = [Frame(0, 0)] * 9 + [FinalFrame(5, 5, 10)] self._assert_score_equals(frames, 20)
def test_final_frame_two_strikes(self): ''' Two strikes on the final frame ''' frames = [Frame(0, 0)] * 9 + [FinalFrame(10, 10, 1)] self._assert_score_equals(frames, 21)