def test_to_json_function_returns_in_json_format(self): game = Game() team1 = Team('team1', (Person('p1'), Person('p2'))) team2 = Team('team2', (Person('p3'), Person('p4'))) team1.teammates[0].cards = [ Card(value, 'C') for value in [val for val in '789TJQKA'] ] team1.teammates[1].cards = [ Card(value, 'D') for value in [val for val in '789TJQKA'] ] team2.teammates[0].cards = [ Card(value, 'H') for value in [val for val in '789TJQKA'] ] team2.teammates[1].cards = [ Card(value, 'S') for value in [val for val in '789TJQKA'] ] game.team1 = team1 game.team2 = team2 teams = (team1, team2) game.json_history = game.add_to_json() result = game.to_json() expected = json.dumps(game.json_history, indent=4) self.assertEqual(result, expected)
def test_cards_comparison_greater_than_works_correctly_for_non_numbers_cards( self): card = Card('K', 'D') card1 = Card('J', 'S') result = card > card1 self.assertEqual(result, True)
def test_cards_comparison_less_or_equal_works_correctly_for_non_numbers_cards_with_non_equal_cards( self): card = Card('T', 'D') card1 = Card('J', 'S') result = card <= card1 self.assertEqual(result, True)
def test_cards_comparison_greater_or_equal_works_correctly_for_numbers_cards_with_equal_cards( self): card = Card('7', 'D') card1 = Card('7', 'S') result = card >= card1 self.assertEqual(result, True)
def test_cards_comparison_less_than_works_correctly_for_numbers_cards( self): card = Card('7', 'D') card1 = Card('8', 'S') result = card < card1 self.assertEqual(result, True)
def test_cards_comparison_greater_than_works_correctly_for_number_and_non_number_cards( self): card = Card('J', 'D') card1 = Card('9', 'S') result = card > card1 opposite_result = card1 > card self.assertEqual(result, True) self.assertEqual(opposite_result, False)
def test_add_to_json_with_more_rounds_returns_dict_with_both_new_and_old_data( self): game = Game() team1 = Team('team1', (Person('p1'), Person('p2'))) team2 = Team('team2', (Person('p3'), Person('p4'))) round_ = 0 expected = {} for i in range(2): team1.teammates[0].cards = [ Card(value, 'C') for value in [val for val in '789TJQKA'] ] team1.teammates[1].cards = [ Card(value, 'D') for value in [val for val in '789TJQKA'] ] team2.teammates[0].cards = [ Card(value, 'H') for value in [val for val in '789TJQKA'] ] team2.teammates[1].cards = [ Card(value, 'S') for value in [val for val in '789TJQKA'] ] game.team1 = team1 game.team2 = team2 teams = (team1, team2) game.json_history = game.add_to_json() expected['game 1:'] = {f'round {round_}:': {}} for i in range(2): expected['game 1:'][f'round {round_}:'][teams[i].name] = {} for j in range(2): team = teams[i] p = team.teammates[j] expected['game 1:'][f'round {round_}:'][team.name][ p.name] = {} expected['game 1:'][f'round {round_}:'][team.name][ p.name] = { 'cards': p.cards, 'announcements': p.announcements, 'points': p.points } round_ += 1 #self.maxDiff = None self.assertEqual(expected, game.json_history)
def test_shuffle_function_should_return_shuffled_list_of_Card(self): cards = [ Card(value, paint) for value in [val for val in '79TJQKA'] for paint in [p for p in 'CDHS'] ] shuffled_cards = Utls.shuffle() self.assertIsNotNone(shuffled_cards) self.assertNotEqual(cards, shuffled_cards)
def test_game_write_json_creates_file_data_json(self): game = Game() team1 = Team('team1', (Person('p1'), Person('p2'))) team2 = Team('team2', (Person('p3'), Person('p4'))) round_ = 0 expected = {} for i in range(2): team1.teammates[0].cards = [ Card(value, 'C') for value in [val for val in '789TJQKA'] ] team1.teammates[1].cards = [ Card(value, 'D') for value in [val for val in '789TJQKA'] ] team2.teammates[0].cards = [ Card(value, 'H') for value in [val for val in '789TJQKA'] ] team2.teammates[1].cards = [ Card(value, 'S') for value in [val for val in '789TJQKA'] ] game.team1 = team1 game.team2 = team2 teams = (team1, team2) game.json_history = game.add_to_json() expected['game 1:'] = {f'round {round_}:': {}} for i in range(2): expected['game 1:'][f'round {round_}:'][teams[i].name] = {} for j in range(2): team = teams[i] p = team.teammates[j] expected['game 1:'][f'round {round_}:'][team.name][ p.name] = {} expected['game 1:'][f'round {round_}:'][team.name][ p.name] = { 'cards': p.cards, 'announcements': p.announcements, 'points': p.points } game.jsoned = game.to_json() game.write_json() round_ += 1
def test_checking_for_belote_function_should_return_list_of_belotes(self): team1 = Team('Malinka', (Person('Ivan'), Person('Gosho'))) team1.teammates[0].cards = [ Card('9', 'D'), Card('Q', 'D'), Card('K', 'D'), Card('Q', 'C'), Card('K', 'S'), Card('Q', 'S'), Card('A', 'H'), Card('7', 'D'), Card('J', 'H'), Card('8', 'C') ] sorted_list = Utls.sort_cards(team1.teammates[0].cards) belote_list = Utls.check_if_there_is_belote(sorted_list) self.assertEqual(belote_list, [['Belote', 'D'], ['Belote', 'S']])
def test_add_to_json_with_1_round_only_returns_new_dict(self): game = Game() team1 = Team('team1', (Person('p1'), Person('p2'))) team2 = Team('team2', (Person('p3'), Person('p4'))) team1.teammates[0].cards = [ Card(value, 'C') for value in [val for val in '789TJQKA'] ] team1.teammates[1].cards = [ Card(value, 'D') for value in [val for val in '789TJQKA'] ] team2.teammates[0].cards = [ Card(value, 'H') for value in [val for val in '789TJQKA'] ] team2.teammates[1].cards = [ Card(value, 'S') for value in [val for val in '789TJQKA'] ] game.team1 = team1 game.team2 = team2 teams = (team1, team2) game.json_history = game.add_to_json() expected = {} expected['game 1:'] = {'round 1:': {}} for i in range(2): expected['game 1:']['round 1:'][teams[i].name] = {} for j in range(2): team = teams[i] p = team.teammates[j] expected['game 1:']['round 1:'][team.name][p.name] = {} expected['game 1:']['round 1:'][team.name][ p.name]['cards'] = p.cards expected['game 1:']['round 1:'][team.name][ p.name]['announcements'] = p.announcements expected['game 1:']['round 1:'][team.name][ p.name]['points'] = p.points self.maxDiff = None self.assertEqual(game.json_history, expected)
def test_sorting_cards_should_returns_sorted_list_of_cards(self): team1 = Team('Malinka', (Person('Ivan'), Person('Gosho'))) team1.teammates[0].cards = [ Card('9', 'D'), Card('J', 'C'), Card('K', 'S'), Card('Q', 'S'), Card('A', 'H'), Card('7', 'D'), Card('J', 'H'), Card('8', 'C') ] result = Utls.sort_cards(team1.teammates[0].cards) self.assertEqual(str(result), '[8 ♣, 11 ♣, 7 ♦, 9 ♦, 11 ♥, 14 ♥, 12 ♠, 13 ♠]')
def test_checking_if_there_is_carre_in_the_cards_should_return_list_of_carres( self): team1 = Team('Malinka', (Person('Ivan'), Person('Gosho'))) team1.teammates[0].cards = [ Card('9', 'C'), Card('9', 'D'), Card('9', 'H'), Card('9', 'S'), Card('7', 'S'), Card('7', 'D') ] sorted_list = Utls.sort_cards(team1.teammates[0].cards) carres_list = Utls.check_if_there_is_carre(sorted_list) self.assertEqual(carres_list, [['Carre', '9']])
def test_card_string_representation_is_as_expected_one(self): card = Card('7', 'D') card1 = Card('K', 'S') self.assertEqual(str(card), '(7,D)') self.assertEqual(str(card1), '(K,S)')
def test_checking_function_if_there_is_quinte_in_the_cards_should_return_list_of_quintes( self): team1 = Team('Malinka', (Person('Ivan'), Person('Gosho'))) team1.teammates[0].cards = [ Card('9', 'D'), Card('Q', 'D'), Card('K', 'D'), Card('T', 'D'), Card('Q', 'C'), Card('J', 'D'), Card('8', 'D'), Card('K', 'S'), Card('Q', 'S'), Card('A', 'H'), Card('7', 'D'), Card('J', 'H'), Card('8', 'C') ] sorted_list = Utls.sort_cards(team1.teammates[0].cards) quinte_list = Utls.check_if_there_is_quinte(sorted_list) self.assertEqual(quinte_list, ['Quinte', 'D', '13'])