示例#1
0
    def test_score(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)

        set_game = Set(player_one, player_two)
        self.assertEqual(set_game.score, '0 - 0, 0 - 0')
        set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score, '0 - 0, 0 - 15')
示例#2
0
    def test_play_game_deuce(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)

        set_game = Set(player_one, player_two)
        for index in range(4):
            set_game.play_game(PLAYER_NAME_ONE)
            set_game.play_game(PLAYER_NAME_TWO)

        self.assertEqual(set_game.score, '0 - 0, Deuce')
示例#3
0
    def test_play_game_advantage(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)

        set_game = Set(player_one, player_two)

        for index in range(4):
            set_game.play_game(PLAYER_NAME_ONE)
            set_game.play_game(PLAYER_NAME_TWO)

        set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score, f'0 - 0, Advantage {PLAYER_NAME_TWO}')
示例#4
0
    def test_play_game_set_winner(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)
        player_two.game = 5
        player_one.game = 4

        set_game = Set(player_one, player_two)

        for index in range(4):
            set_game.play_game(PLAYER_NAME_TWO)

        self.assertIsInstance(set_game.winner, Player)
示例#5
0
    def point_won_by(self, player: str):
        """ Assuming that there is not a winner yet and the player is valid """
        # Check if anyone won the set
        if self.__set_game.winner:
            # If someone won two set it is a match winner
            if self.__set_game.winner.set == 2:
                self.winner = self.__set_game.winner
                return None

            # Start a new set of games
            self.__set_game = Set(self.player_one, self.player_two)

        self.__set_game.play_game(player)
        self.score = self.__set_game.score
示例#6
0
    def test_play_game_tie_breaker_score(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)
        player_two.game = 6
        player_one.game = 6

        set_game = Set(player_one, player_two)
        self.assertEqual(set_game.tie_breaker(), True)

        for index in range(11):
            set_game.play_game(PLAYER_NAME_TWO)
            set_game.play_game(PLAYER_NAME_ONE)

        # Check game score before decide the winner
        self.assertEqual(set_game.score, '6 - 6, 11 - 11')
示例#7
0
    def test_play_game_win(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)

        set_game = Set(player_one, player_two)

        for index in range(3):
            set_game.play_game(PLAYER_NAME_TWO)

        # Check game score before decide the winner
        self.assertEqual(set_game.score, '0 - 0, 0 - 40')

        # Player two should win the game
        set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score, f'0 - 1, Winner {PLAYER_NAME_TWO}')
示例#8
0
    def test_play_game_additional_game(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)
        player_two.game = 6
        player_one.game = 5

        set_game = Set(player_one, player_two)
        self.assertEqual(set_game.tie_breaker(), False)

        for index in range(3):
            set_game.play_game(PLAYER_NAME_TWO)

        self.assertEqual(set_game.score, '5 - 6, 0 - 40')
        set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score,
                         f'Winner {PLAYER_NAME_TWO} Set: 0 - 1 | Game: 5 - 7')
        self.assertIsInstance(set_game.winner, Player)
示例#9
0
    def test_play_game_tie_breaker_set_winner(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)
        player_two.game = 6
        player_one.game = 6

        set_game = Set(player_one, player_two)
        self.assertEqual(set_game.tie_breaker(), True)

        for index in range(8):
            set_game.play_game(PLAYER_NAME_TWO)
            set_game.play_game(PLAYER_NAME_ONE)

        # Check game score before decide the winner
        self.assertEqual(set_game.score, '6 - 6, 8 - 8')

        set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score, '6 - 6, 8 - 9')

        set_game.play_game(PLAYER_NAME_TWO)
        self.assertIsInstance(set_game.winner, Player)
        self.assertEqual(set_game.score,
                         f'Winner {PLAYER_NAME_TWO} Set: 0 - 1 | Game: 6 - 7')
示例#10
0
    def test_play_game_new_games(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)

        set_game = Set(player_one, player_two)
        self.assertEqual(set_game.tie_breaker(), False)

        for index in range(3):
            set_game.play_game(PLAYER_NAME_TWO)

        self.assertEqual(set_game.score, '0 - 0, 0 - 40')
        set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score, f'0 - 1, Winner {PLAYER_NAME_TWO}')

        for index in range(3):
            set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score, '0 - 1, 0 - 40')
        set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score, f'0 - 2, Winner {PLAYER_NAME_TWO}')

        for index in range(15):
            set_game.play_game(PLAYER_NAME_TWO)
        self.assertEqual(set_game.score, '0 - 5, 0 - 40')
示例#11
0
    def test_tie_breaker(self):
        player_one = Player(PLAYER_NAME_ONE)
        player_two = Player(PLAYER_NAME_TWO)

        set_game = Set(player_one, player_two)
        self.assertEqual(set_game.tie_breaker(), False)
示例#12
0
""" Module for using json_serializer """
import json
from modules.json_serializer import JSONSerializer
from classes.example import Person
from classes.set import Set

#Example
first = Person(1, "Jack")
second = Person(2, "Jill")
third = Person(3, "Aleks")
first.id_person = second
first.children.append(second)
first.children.append(third)
print(first.__class__)
JSONSerializer.serialize(first, 'Jack')
#Set
set_on_avl_tree = Set('int')
set_on_avl_tree.add('15')
set_on_avl_tree.add('167')
set_on_avl_tree.add('4')
set_on_avl_tree.add('200')
JSONSerializer.serialize(set_on_avl_tree, 'Set')
示例#13
0
 def __init__(self, player_one: Player, player_two: Player):
     self.player_one = player_one
     self.player_two = player_two
     self.__set_game = Set(self.player_one, self.player_two)
     self.score = None
     self.winner = None