コード例 #1
0
    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),
        ])
コード例 #2
0
    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)
コード例 #3
0
    def testGetWinners_Hits(self):
        players = [Player('A'), Player('B'), Player('C')]
        classHits = HitsMatch(len(players), players)

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

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

        # Test on 2 and more winners
        classHits._results_table = [
            [1, 4, 1],
            [1, 4, 1],
            [1, 2, 1],
        ]
        self.assertEqual(classHits.get_winners(), [players[0], players[2]])