Example #1
0
    def test_instructions_example_3(self):
        hand = [1, 2, 3, 5, 9]
        want = False
        got = approx_average_is_average(hand)

        self.assertEqual(
            want,
            got,
            msg=f'Expected {want} but got an incorrect result: {got!r}')
Example #2
0
    def test_other_false(self):
        hand = [2, 3, 4, 7, 8]
        want = False
        got = approx_average_is_average(hand)

        self.assertEqual(
            want,
            got,
            msg=f'Expected {want} but got an incorrect result: {got!r}')
Example #3
0
    def test_instructions_example_2(self):
        hand = [2, 3, 4, 8, 8]
        want = True
        got = approx_average_is_average(hand)

        self.assertEqual(
            want,
            got,
            msg=f'Expected {want} but got an incorrect result: {got!r}')
Example #4
0
    def test_approx_average_is_average(self):

        input_vars = [[0, 1, 5], [3, 6, 9, 12, 150], [1, 2, 3, 5, 9],
                      [2, 3, 4, 7, 8], [1, 2, 3], [2, 3, 4], [2, 3, 4, 8, 8],
                      [1, 2, 4, 5, 8]]

        results = [False, False, False, False, True, True, True, True]

        for variant, (hand, same) in enumerate(zip(input_vars, results),
                                               start=1):
            error_message = f'Hand {hand} {"does" if same else "does not"} yield the same approximate average.'
            with self.subTest(f'variation #{variant}', input=hand,
                              output=same):
                self.assertEqual(same,
                                 approx_average_is_average(hand),
                                 msg=error_message)