def test_winner(player1_score, player2_score, winner): match = Match( 'player1', 'player2', player_one_score=player1_score, player_two_score=player2_score ) assert match.winner() is winner
def test_deuce(player1_score, player2_score, deuce): match = Match( 'player1', 'player2', player_one_score=player1_score, player_two_score=player2_score ) assert match.deuce() is deuce
def test_advantage(player1_score, player2_score, advantage): match = Match( 'player1', 'player2', player_one_score=player1_score, player_two_score=player2_score ) assert match.advantage() is advantage
def test_get_set_score(player1_score, player2_score, set_score): match = Match( 'player1', 'player2', player_one_score=player1_score, player_two_score=player2_score ) match.get_game_score() == set_score
def test_get_player_having_highest_score( player1_score, player2_score, high_score_player ): match = Match( 'player1', 'player2', player_one_score=player1_score, player_two_score=player2_score ) assert match.get_player_having_highest_score() == high_score_player
from tennis.match import Match match = Match("player 1", "player 2") match.point_won_by("player 1") match.point_won_by("player 2") # this will return "0-0, 15-15" match.score() match.point_won_by("player 1") match.point_won_by("player 1") # this will return "0-0, 40-15" match.score() match.point_won_by("player 2") match.point_won_by("player 2") # this will return "0-0, Deuce" match.score() match.point_won_by("player 1") # this will return "0-0, Advantage player 1" match.score() match.point_won_by("player 1") # this will return "1-0" match.score()
def test_point_won_by(initial_score, score_after_winning): match = Match('player1', 'player2', player_one_score=initial_score) match.point_won_by('player1') assert match.player_one_score == score_after_winning
def test_point_won_by_sets_7_5(self): """ Winning match 7-5 """ match = Match('p1', 'p2') for _ in range(20): match.point_won_by('p1') self.assertEqual(match.__str__(), '5-0') for _ in range(20): match.point_won_by('p2') self.assertEqual(match.__str__(), '5-5') for _ in range(4): match.point_won_by('p1') self.assertEqual(match.__str__(), '6-5') for _ in range(4): match.point_won_by('p1') self.assertEqual(match.__str__(), 'p1 is the winner')
def test_point_won_by_tie_break(self): """ Winning match by tie break point """ match = Match('p1', 'p2') for _ in range(20): match.point_won_by('p1') self.assertEqual(match.__str__(), '5-0') for _ in range(20): match.point_won_by('p2') self.assertEqual(match.__str__(), '5-5') for _ in range(4): match.point_won_by('p1') self.assertEqual(match.__str__(), '6-5') for _ in range(4): match.point_won_by('p2') self.assertEqual(match.__str__(), '6-6') # Tie break start match.point_won_by('p1') self.assertEqual(match.__str__(), '6-6, 1-0') match.point_won_by('p2') self.assertEqual(match.__str__(), '6-6, 1-1') match.point_won_by('p2') for _ in range(4): match.point_won_by('p1') self.assertEqual(match.__str__(), '6-6, 5-2') # Match point for _ in range(5): match.point_won_by('p2') self.assertEqual(match.__str__(), 'p2 is the winner')
def test_point_won_by_sets_6_4(self): """ Normal winning match """ match = Match('p1', 'p2') for _ in range(20): match.point_won_by('p1') self.assertEqual(match.__str__(), '5-0') for _ in range(16): match.point_won_by('p2') self.assertEqual(match.__str__(), '5-4') for _ in range(4): match.point_won_by('p1') self.assertEqual(match.__str__(), 'p1 is the winner') match.point_won_by('p1') self.assertEqual(match.__str__(), 'p1 is the winner')
def test_point_won_by_advantage(self): """ Winning game by advantage """ match = Match('p1', 'p2') match.point_won_by('p1') match.point_won_by('p1') match.point_won_by('p1') match.point_won_by('p2') match.point_won_by('p2') match.point_won_by('p2') self.assertEqual(match.__str__(), '0-0, Deuce') match.point_won_by('p1') self.assertEqual(match.__str__(), '0-0, Advantage p1') match.point_won_by('p2') self.assertEqual(match.__str__(), '0-0, Deuce') match.point_won_by('p2') match.point_won_by('p2') self.assertEqual(match.__str__(), '0-1')
def test_point_won_by_tie_break_match_point(self): """ Winning match by tie break point special """ match = Match('p1', 'p2') for _ in range(20): match.point_won_by('p1') self.assertEqual(match.__str__(), '5-0') for _ in range(20): match.point_won_by('p2') self.assertEqual(match.__str__(), '5-5') for _ in range(4): match.point_won_by('p1') self.assertEqual(match.__str__(), '6-5') for _ in range(4): match.point_won_by('p2') self.assertEqual(match.__str__(), '6-6') # Tie break start for _ in range(6): match.point_won_by('p1') self.assertEqual(match.__str__(), '6-6, 6-0') for _ in range(6): match.point_won_by('p2') self.assertEqual(match.__str__(), '6-6, 6-6') match.point_won_by('p1') match.point_won_by('p1') self.assertEqual(match.__str__(), 'p1 is the winner')
def test_point_won_by_normal(self): """ Normal winning game """ match = Match('p1', 'p2') match.point_won_by('p1') self.assertEqual(match.__str__(), '0-0, 15-0') match.point_won_by('p1') self.assertEqual(match.__str__(), '0-0, 30-0') match.point_won_by('p1') self.assertEqual(match.__str__(), '0-0, 40-0') match.point_won_by('p2') self.assertEqual(match.__str__(), '0-0, 40-15') match.point_won_by('p2') self.assertEqual(match.__str__(), '0-0, 40-30') match.point_won_by('p1') self.assertEqual(match.__str__(), '1-0')
def match_runner(): match = Match("player 1", "player 2") match.point_won_by("player 1") match.point_won_by("player 2") # this will return "0-0, 15-15" match.score() match.point_won_by("player 1") match.point_won_by("player 1") # this will return "0-0, 40-15" match.score() match.point_won_by("player 2") match.point_won_by("player 2") # this will return "0-0, Deuce" match.score() match.point_won_by("player 1") # this will return "0-0, Advantage player 1" match.score() match.point_won_by("player 1") # this will return "1-0" match.score()