Пример #1
0
 def test_init(self):
     players = [Player('A'), Player('B')]
     m = HolesMatch(4, players)
     m.hit(True)
     self.assertEqual(m.flag_hit, True)
     self.assertEqual(m.round, 0)
     self.assertEqual(m.player_change, deque([0,1]))
Пример #2
0
    def test_hit(self):
        players = [Player('A'), Player('B')]
        m = HolesMatch(2, players)
        for _ in range(10):
            m.hit()
            m.hit()

        self.assertEqual(m.score_list,[[0,0],[None,None]])
Пример #3
0
 def test_get_winners(self):
     players = [Player('A'), Player('B')]
     m = HolesMatch(2, players)
     m.hit()
     m.hit(True)
     m.hit(True)
     m.hit()
     self.assertEqual(m.get_winners(),[players[1]])
Пример #4
0
    def testInit(self):
        players = [Player('A'), Player('B'), Player('C')]
        # Wrong INIT
        with self.assertRaises(TypeError):
            classObj = HitsMatch()

        with self.assertRaises(TypeError):
            classObj = HolesMatch()

        with self.assertRaises(TypeError):
            classObj = HitsMatch(players)

        classHits = HitsMatch(len(players), players)
        self.assertEqual(classHits._results_table, [
            [None, None, None],
            [None, None, None],
            [None, None, None],
        ])

        classHoles = HolesMatch(0, [])
        self.assertEqual(classHoles.finished, 1)
Пример #5
0
    def testGetWinners_Holes(self):
        players = [Player('A'), Player('B'), Player('C')]
        classHoles = HolesMatch(len(players), players)

        classHoles._finished = False
        with self.assertRaises(RuntimeError):
            classHoles.get_winners()

        # Test on 1 winner
        classHoles._results_table = [
            [1, 0, 1],
            [1, 0, 1],
            [1, 0, 0],
        ]
        classHoles._finished = True
        self.assertEqual(classHoles.get_winners(), [players[0]])

        # Test on 2 and more winners
        classHoles._results_table = [
            [1, 0, 1],
            [1, 0, 1],
            [1, 1, 1],
        ]
        self.assertEqual(classHoles.get_winners(), [players[0], players[2]])
    def test_scenario(self):
        players = [Player('A'), Player('B'), Player('C')]
        m = HolesMatch(3, players)

        self._first_hole(m)
        self._second_hole(m)

        with self.assertRaises(RuntimeError):
            m.get_winners()

        self._third_hole(m)

        with self.assertRaises(RuntimeError):
            m.hit()

        self.assertEqual(m.get_winners(), [players[0], players[2]])
Пример #7
0
 def test_change_round(self):
     players = [Player('A'), Player('B')]
     m = HolesMatch(4, players)
     m.hit()
     m.hit()
     self.assertEqual(m.round,1)
Пример #8
0
 def test_change_hole(self):
     players = [Player('A'), Player('B')]
     m = HolesMatch(4, players)
     m.change_hole()
     self.assertEqual(m.cur_hole,1)
     self.assertEqual(m.player_change,deque([1,0]))
Пример #9
0
 def test_get_table(self):
     players = [
         Player('A'),
         Player('B'),
         Player('E'),
     ]
     m = HitsMatch(2, players)
     k = HolesMatch(2, players)
     self.assertEqual(m.get_table(), [('A', 'B', 'E'), (None, None, None),
                                      (None, None, None)])
     self.assertEqual(k.get_table(), [('A', 'B', 'E'), (None, None, None),
                                      (None, None, None)])
     m.hit(True)
     m.hit(True)
     self.assertEqual(m.get_table(), [('A', 'B', 'E'), (1, 1, None),
                                      (None, None, None)])
     k.hit(True)  # 1
     k.hit()  # 2
     k.hit()  # 3
     k.hit(True)  # 2
     k.hit()  # 3
     self.assertEqual(k.get_table(), [('A', 'B', 'E'), (1, 0, 0),
                                      (None, 1, 0)])
Пример #10
0
 def test_get_winners(self):
     players = [Player('A'), Player('B'), Player('E'), Player('D')]
     m = HitsMatch(3, players)
     k = HolesMatch(3, players)
     with self.assertRaises(RuntimeError):
         m.get_winners()
     with self.assertRaises(RuntimeError):
         k.get_winners()
     m.hit(True)
     k.hit(True)
     with self.assertRaises(RuntimeError):
         m.get_winners()
     with self.assertRaises(RuntimeError):
         k.get_winners()
     for _ in range(11):
         m.hit(True)
     self.assertEqual(m.get_winners(),
                      [players[0], players[1], players[2], players[3]])
     for _ in range(11):
         k.hit(True)
     self.assertEqual(k.get_winners(),
                      [players[0], players[1], players[2], players[3]])
Пример #11
0
 def setUp(self):
     self._players = [Player('A'), Player('B'), Player('C')]
     self._m = HolesMatch(3, self._players)
 def setUp(self):
     self.players_list = [Player('A'), Player('B'), Player('C')]
     # TODO: tuple instead of list
     self.players_names_tuple = tuple(player.name
                                      for player in self.players_list)
     self.holes_match = HolesMatch(3, self.players_list)
class TestHolesMatch(unittest.TestCase):
    def setUp(self):
        self.players_list = [Player('A'), Player('B'), Player('C')]
        # TODO: tuple instead of list
        self.players_names_tuple = tuple(player.name
                                         for player in self.players_list)
        self.holes_match = HolesMatch(3, self.players_list)

    def test_one_not_successful_hit_on_first_hole(self):
        """
        Checks, that after unsuccessful hit nothing will be showed in the table
        """
        self.holes_match.hit()  # 1
        self.assertEqual([
            self.players_names_tuple, (None, None, None), (None, None, None),
            (None, None, None)
        ], self.holes_match.get_table())

    def test_one_successful_hit_on_first_hole(self):
        """
        Checks that first hit on the first hole will be made by a first player
        """
        self.holes_match.hit(success=True)  # 1
        self.assertEqual([
            self.players_names_tuple, (1, None, None), (None, None, None),
            (None, None, None)
        ], self.holes_match.get_table())

    def test_auto_closed_first_hole_by_one_successful_hit(self):
        """
        Checks that after one successful hit by one of the players
        hole will be closed and other players will get zero
        """
        self.holes_match.hit()  # 1
        self.holes_match.hit(success=True)  # 2
        self.holes_match.hit()  # 3

        self.assertEqual([
            self.players_names_tuple, (0, 1, 0), (None, None, None),
            (None, None, None)
        ], self.holes_match.get_table())

    def test_hole_auto_closing_after_reaching_the_limit_of_hits(self):
        """
        Checks that hole will close automatically after 30 unsuccessful hits
        """
        for _ in range(10):
            for _ in range(3):
                self.holes_match.hit()  # 2, 3, 1
        self.assertEqual([
            self.players_names_tuple, (0, 0, 0), (None, None, None),
            (None, None, None)
        ], self.holes_match.get_table())

    def _close_first_hole_with_successful_first_hits(self):
        self.holes_match.hit(success=True)  # 1
        self.holes_match.hit(success=True)  # 2
        self.holes_match.hit(success=True)  # 3

    def test_one_successful_hit_on_second_hole(self):
        """
        Checks that first hit on the second hole will be made by a second player
        """
        self._close_first_hole_with_successful_first_hits()
        self.holes_match.hit(success=True)  # 2 because it's a second hole
        self.assertEqual([
            self.players_names_tuple, (1, 1, 1), (None, 1, None),
            (None, None, None)
        ], self.holes_match.get_table())

    def test_auto_closed_second_hole_by_one_successful_hit(self):
        """
        Checks that after one successful hit by one of the players
        hole will be closed and other players will get zero
        """
        self._close_first_hole_with_successful_first_hits()

        self.holes_match.hit()  # 2
        self.holes_match.hit(success=True)  # 3
        self.holes_match.hit()  # 1

        self.assertEqual([
            self.players_names_tuple, (1, 1, 1), (0, 0, 1), (None, None, None)
        ], self.holes_match.get_table())

    def _close_second_hole_with_successful_first_hits(self):
        self.holes_match.hit(success=True)  # 2
        self.holes_match.hit(success=True)  # 3
        self.holes_match.hit(success=True)  # 1

    def test_one_successful_hit_on_third_hole(self):
        """
        Checks that first hit on the third hole will be made by a third player
        """
        self._close_first_hole_with_successful_first_hits()
        self._close_second_hole_with_successful_first_hits()

        self.holes_match.hit(success=True)  # 3 because it's a third hole
        self.assertEqual(
            [self.players_names_tuple, (1, 1, 1), (1, 1, 1), (None, None, 1)],
            self.holes_match.get_table())

    def _close_third_hole_with_successful_first_hits(self):
        self.holes_match.hit(success=True)  # 3
        self.holes_match.hit(success=True)  # 1
        self.holes_match.hit(success=True)  # 2

    def test_runtime_error_by_hit_on_finished_game(self):
        self._close_first_hole_with_successful_first_hits()
        self._close_second_hole_with_successful_first_hits()
        self._close_third_hole_with_successful_first_hits()

        with self.assertRaises(RuntimeError):
            self.holes_match.hit()

    def test_runtime_error_by_get_winners_on_unfinished_game(self):
        with self.assertRaises(RuntimeError):
            self.holes_match.get_winners()

    def test_get_winners_1(self):
        self._close_first_hole_with_successful_first_hits()
        self._close_second_hole_with_successful_first_hits()
        self._close_third_hole_with_successful_first_hits()

        self.assertEqual(
            [self.players_names_tuple, (1, 1, 1), (1, 1, 1), (1, 1, 1)],
            self.holes_match.get_table())

        self.assertEqual(self.holes_match.get_winners(), self.players_list)

    def test_get_winners_2(self):
        self.holes_match.hit(success=True)
        self.holes_match.hit()
        self.holes_match.hit(success=True)
        self._close_second_hole_with_successful_first_hits()
        self._close_third_hole_with_successful_first_hits()

        self.assertEqual(
            [self.players_names_tuple, (1, 0, 1), (1, 1, 1), (1, 1, 1)],
            self.holes_match.get_table())

        self.assertEqual(self.holes_match.get_winners(),
                         [self.players_list[0], self.players_list[2]])

    def test_get_winners_3(self):
        self.holes_match.hit()
        self.holes_match.hit()
        self.holes_match.hit(success=True)
        self._close_second_hole_with_successful_first_hits()
        self._close_third_hole_with_successful_first_hits()

        self.assertEqual(
            [self.players_names_tuple, (0, 0, 1), (1, 1, 1), (1, 1, 1)],
            self.holes_match.get_table())

        self.assertEqual(self.holes_match.get_winners(),
                         [self.players_list[2]])
Пример #14
0
    def testHitInHolesMatch(self):
        players = [Player('A'), Player('B'), Player('C')]
        classHoles = HolesMatch(len(players), players)

        # Test when last player scores
        classHoles.hit()
        classHoles.hit()
        classHoles.hit(True)

        self.assertEqual(classHoles._results_table, [
            [0, 0, 1],
            [None, None, None],
            [None, None, None],
        ])

        # Test when pre-last player scores
        classHoles.hit()
        classHoles.hit(True)
        classHoles.hit()
        self.assertEqual(classHoles._results_table, [
            [0, 0, 1],
            [0, 0, 1],
            [None, None, None],
        ])

        # Test for 10 misses
        for _ in range(10):
            for _ in range(3):
                classHoles.hit()

        self.assertEqual(classHoles._results_table, [
            [0, 0, 1],
            [0, 0, 1],
            [0, 0, 0],
        ])