def testNextHole(self):
        players = [Player('A'), Player('B'), Player('C')]
        classHits = HitsMatch(10, players)

        classHits._current_hole = 1
        for player in classHits._players_array:
            player.hits_no_more = 1

        # Switch to last hole
        classHits._switch_to_next_hole()

        self.assertEqual(classHits._current_hole, 2)
        for player in classHits._players_array:
            self.assertEqual(player.hits_no_more, 0)
        self.assertEqual(classHits._finished, False)
        self.assertEqual(classHits._current_player, 2)

        # Switch to the holenum that is > than number of players, e.g. next player = 0
        classHits._switch_to_next_hole()
        self.assertEqual(classHits._current_hole, 3)
        self.assertEqual(classHits._finished, False)
        self.assertEqual(classHits._current_player, 0)

        # Switch to the end of game
        classHits._current_hole = 9
        classHits._switch_to_next_hole()
        self.assertEqual(classHits._current_hole, 10)
        self.assertEqual(classHits._finished, True)
    def testHitInHitsMatch(self):
        players = [Player('A'), Player('B'), Player('C')]
        classHits = HitsMatch(len(players), players)

        # Test usual bad hit for 0 player
        classHits._results_table = [
            [1, 8, 2],
            [1, 8, 0],
            [None, None, None],
        ]

        classHits._current_player = 0
        classHits._current_hole = 2
        classHits.hit()

        self.assertEqual(classHits._results_table, [
            [1, 8, 2],
            [1, 8, 0],
            [1, None, None],
        ])

        for player in classHits._players_array:
            self.assertEqual(player.hits_no_more, 0)

        # Test usual good hit for 1 player
        classHits.hit(True)
        self.assertEqual(classHits._results_table, [
            [1, 8, 2],
            [1, 8, 0],
            [1, 1, None],
        ])

        self.assertEqual(classHits._players_array[0].hits_no_more, 0)
        self.assertEqual(classHits._players_array[1].hits_no_more, 1)
        self.assertEqual(classHits._players_array[2].hits_no_more, 0)

        # Test no hit for 9 points bad hit for 1 player => 10 points
        classHits._players_array[1].hits_no_more = 0
        classHits._current_player = 1
        classHits._current_hole = 0
        classHits.hit()
        self.assertEqual(classHits._results_table, [
            [1, 10, 2],
            [1, 8, 0],
            [1, 1, None],
        ])
        self.assertEqual(classHits._players_array[1].hits_no_more, 1)

        # Test no hit for 8 points GOOD hit for 1 player => 9 points
        classHits._players_array[1].hits_no_more = 0
        classHits._current_player = 1
        classHits._current_hole = 1
        classHits.hit(True)
        self.assertEqual(classHits._results_table, [
            [1, 10, 2],
            [1, 9, 0],
            [1, 1, None],
        ])
        self.assertEqual(classHits._players_array[1].hits_no_more, 1)
    def testGetTable(self):
        players = [Player('A'), Player('B'), Player('C')]
        classHits = HitsMatch(len(players), players)

        # Current hole is not finished and some players did not ended playing, but scored
        classHits._results_table = [
            [1, 0, 1],
            [1, 2, None],
            [None, None, None],
        ]

        classHits._current_hole = 1
        for player in classHits._players_array:
            player.hits_no_more = 0
        classHits._players_array[0].hits_no_more = 1
        self.assertEqual(classHits.get_table(), [
            ('A', 'B', 'C'),
            (1, 0, 1),
            (1, None, None),
            (None, None, None),
        ])

        # Current hole is finished
        classHits._results_table = [
            [1, 0, 1],
            [1, 2, 0],
            [None, None, None],
        ]

        classHits._current_hole = 2
        for player in classHits._players_array:
            player.hits_no_more = 0
        self.assertEqual(classHits.get_table(), [
            ('A', 'B', 'C'),
            (1, 0, 1),
            (1, 2, 0),
            (None, None, None),
        ])

        # Game finished
        classHits._results_table = [
            [1, 0, 1],
            [1, 2, 0],
            [1, 1, 1],
        ]

        classHits._current_hole = 3
        self.assertEqual(classHits.get_table(), [
            ('A', 'B', 'C'),
            (1, 0, 1),
            (1, 2, 0),
            (1, 1, 1),
        ])
    def testSetNextUser(self):
        players = [Player('A'), Player('B'), Player('C')]
        classHits = HitsMatch(len(players), players)

        # Should set next player 2(last), but not hole
        classHits._current_player = 1
        classHits._current_hole = 1
        classHits._set_next_player_and_hole_if_needed()

        self.assertEqual(classHits._current_hole, 1)
        self.assertEqual(classHits._current_player, 2)

        # Should set next player 0(first)!!!, but not hole
        classHits._set_next_player_and_hole_if_needed()
        self.assertEqual(classHits._current_hole, 1)
        self.assertEqual(classHits._current_player, 0)

        # Should set next player 2(= number of hole), AND next hole 2
        for player in classHits._players_array:
            player.hits_no_more = 1
        classHits._set_next_player_and_hole_if_needed()
        self.assertEqual(classHits._current_hole, 2)
        self.assertEqual(classHits._current_player, 2)

        # Should set finished state
        for player in classHits._players_array:
            player.hits_no_more = 1
        classHits._set_next_player_and_hole_if_needed()
        self.assertEqual(classHits.finished, True)