Example #1
0
    def test_point_won_by(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)
        match = Match(player_one, player_two)
        match.point_won_by(PLAYER_NAME_TWO)

        self.assertEqual(match.score, '0 - 0, 0 - 15')
Example #2
0
    def test_match_winner_set_one(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)
        match = Match(player_one, player_two)
        game_points = 4
        set_points = 6

        for index in range(game_points * set_points):
            match.point_won_by(PLAYER_NAME_TWO)

        self.assertEqual(match.score,
                         f'Winner {PLAYER_NAME_TWO} Set: 0 - 1 | Game: 0 - 6')
Example #3
0
    def test_match_winner_set_one_tie_breaker(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)
        match = Match(player_one, player_two)
        game_points = 4
        set_points = 5

        # Player two winning 5 games
        for index in range(game_points * set_points):
            match.point_won_by(PLAYER_NAME_TWO)

        self.assertEqual(match.score, f'0 - 5, Winner {PLAYER_NAME_TWO}')

        # Player one winning 5 games
        for index in range(game_points * set_points):
            match.point_won_by(PLAYER_NAME_ONE)

        self.assertEqual(match.score, f'5 - 5, Winner {PLAYER_NAME_ONE}')

        # Player two winning 6 games
        for index in range(game_points):
            match.point_won_by(PLAYER_NAME_TWO)

        self.assertEqual(match.score, f'5 - 6, Winner {PLAYER_NAME_TWO}')

        # Player one winning 6 games
        for index in range(game_points):
            match.point_won_by(PLAYER_NAME_ONE)

        self.assertEqual(match.score, f'6 - 6, Winner {PLAYER_NAME_ONE}')

        # Tie breaker game
        for index in range(7):
            match.point_won_by(PLAYER_NAME_ONE)
            match.point_won_by(PLAYER_NAME_TWO)

        self.assertEqual(match.score, f'6 - 6, 7 - 7')

        # Tie breaker player one winner
        match.point_won_by(PLAYER_NAME_ONE)
        match.point_won_by(PLAYER_NAME_ONE)

        self.assertEqual(match.score,
                         f'Winner {PLAYER_NAME_ONE} Set: 1 - 0 | Game: 7 - 6')
Example #4
0
from classes.player import Player
from classes.match import Match
from helpers.constant import PLAYER_NAME_ONE, PLAYER_NAME_TWO

player_one = Player(PLAYER_NAME_ONE)
player_two = Player(PLAYER_NAME_TWO)

print('*******************************************************')
print(
    f'********* Playing a game {player_one.name} VS {player_two.name} *********'
)
print('*******************************************************')

match = Match(player_one, player_two)
players = {1: player_one.name, 2: player_two.name}

while True:
    if match.winner:
        print(match.score)
        break

    try:
        player = int(input('Who won the point Player (1) or Player (2):'))
        match.point_won_by(players[player])
    except Exception:
        continue

    print("\n======= SCORE ========")
    print(match.score)
    print("======================\n")