def test_frame_eq_comparison_is_as_expected(self):
        test_frame1 = Frame(4, 6)
        test_frame2 = Frame(4, 6)
        test_frame3 = Frame(2, 5)

        self.assertEqual(test_frame1, test_frame2)
        self.assertNotEqual(test_frame2, test_frame3)
    def test_frame_str_representation_is_as_expected(self):
        test_frame1 = Frame(4, 6)
        test_frame2 = Frame(10, 8)
        test_frame3 = Frame(3, 4)

        self.assertEqual(str(test_frame1), '[Spare]')
        self.assertEqual(str(test_frame2), '[Strike]')
        self.assertEqual(str(test_frame3), '[Open Frame]')
    def test_frame_init_initializes_object_as_expected(self):
        test_frame1 = Frame(4, 6)
        test_frame2 = Frame(10, 0)

        self.assertEqual(getattr(test_frame1, 'first_chance'), 4)
        self.assertEqual(getattr(test_frame1, 'second_chance'), 6)

        self.assertEqual(getattr(test_frame2, 'first_chance'), 10)
        self.assertEqual(getattr(test_frame2, 'second_chance'), 0)
    def test_bowling_game_init_initializes_object_as_expected(self):
        test_argument = [1, 2, 3, 1, 4, 6, 1, 8, 2, 3]
        test_game = BowlingGame(test_argument)

        self.assertEqual(
            getattr(test_game, 'frames'),
            [Frame(1, 2),
             Frame(3, 1),
             Frame(4, 6),
             Frame(1, 8),
             Frame(2, 3)])
    def test_frame_validation_raises_exception_if_first_chance_negative(self):
        exc = None

        try:
            test = Frame(-5, 6)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(
            str(exc), "Invalid number of pins submitted for your first try.")
    def test_frame_validation_raises_exception_if_second_argument_is_not_int(
            self):
        exc = None

        try:
            test = Frame(3, '8')
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Second argument must be of "int" type.')
    def test_frame_validation_raises_exception_if_first_argument_is_not_int(
            self):
        exc = None

        try:
            test = Frame('3', 8)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'First argument must be of "int" type.')
    def test_frame_validation_raises_exception_if_sum_of_chances_greater_than_ten(
            self):
        exc = None

        try:
            test = Frame(3, 8)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(
            str(exc), "You can't take down more than 10 pins in one frame.")
    def test_frame_validation_raises_exception_if_second_chance_greater_than_ten(
            self):
        exc = None

        try:
            test = Frame(3, 16)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(
            str(exc), "Invalid number of pins submitted for your second try.")
示例#10
0
 def test_add_third_roll_validation_error(self):
     frame = Frame()
     frame.add_roll(4)
     frame.add_roll(3)
     msg = ("Adding a third roll to a frame raises a validation error")
     with self.assertRaises(ValueError, msg=msg):
         frame.add_roll(1)
示例#11
0
 def test_roll_validation_error(self):
     frame = Frame()
     msg = "The total number of pins rolled can't exceed 10"
     with self.assertRaises(ValueError, msg=msg):
         frame.add_roll(11)
示例#12
0
 def test_pin_count_validation_error(self):
     frame = Frame()
     frame.add_roll(7)
     msg = "The total of the first and second roll can't exceed 10"
     with self.assertRaises(ValueError, msg=msg):
         frame.add_roll(5)
示例#13
0
 def build_frame(first_roll=0, second_roll=0):
     frame_class = Frame(rolls=[first_roll, second_roll])
     return frame_class
示例#14
0
 def test_empty_frame_score(self):
     frame_class = Frame()
     self.assertEqual(
         frame_class.frame_score(),
         0,
         msg="An empty frame with no rolls should have a score of 0")
 def test_frame_validation_passes_with_correct_input(self):
     test1 = Frame(3, 6)
     test2 = Frame(4, 6)
     test3 = Frame(0, 6)
     test4 = Frame(0, 0)