def test_new_game(self): #checks the function shuffle the list game1 = CardGame(5) game2 = game1.listofcards.copy() game1.newGame() break1 = 0 for i in range(len(game1.listofcards)): if game1.listofcards[i] != game2[i]: break1 += 1 break self.assertTrue(break1 == 1)
def test_init_( self ): #checks the function not starts a game with numofcards is'nt integer try: game = CardGame("ziv") except: pass else: self.fail()
class TestCardGame(TestCase): def setUp(self): self.card_game = CardGame() def test_create_card_game(self): self.assertEqual(len(self.card_game.lst_of_players), 4) for player in self.card_game.lst_of_players: self.assertIsInstance(player, Player) self.assertIsNotNone(self.card_game.num_of_cards) @mock.patch("builtins.print") def test_new_game(self, mocked_print): with mock.patch.object(DeckOfCards, "new_game") as mocked_new_game: self.card_game.new_game() self.assertTrue(mocked_print.called) # Check if print was print all players mocked_new_game.assert_called_with() with mock.patch.object(DeckOfCards, "deal_one") as mocked_deal_one: self.card_game.deal_one() mocked_deal_one.assert_called_with() # Check if deal_one was called def test_print_all_players(self): with mock.patch("games.cards.Player.print") as mocked_player_print: self.card_game.new_game() mocked_player_print.assert_called()
from games.cards.Card import Card from games.cards.Player import Player from games.cards.DeckOfCards import DeckOfCards from games.cards.CardGame import CardGame from random import * #קליטה של סכום כסף התחלתי לכל שחקן amount=randint(5000,10000) print(amount) #קליטה של משחק חדש עם שליחה של כמות קלפים לכל שחקן game1=CardGame(5) game1.newGame() #הדפסה של כל שחקן במשחק עם כמות הכסף שבידו והקלפים שהוא מחזיק for i in game1.players: print(i) #פתיחת משחק - 5 סיבובים for i in range(1,6,1): print(f'Round number {i} has started:') prize=game1.PayRound(i) list1=[] list2=[] pointer=0 #כל שחקן במשחק זורק קלף מהחפיסה שלו for n in game1.players: nameofplayer=game1.players[pointer].name card=(game1.CardsPerRound(pointer)) list1.append(card) list2.append(nameofplayer) print(f'{nameofplayer} throw the card: {card}') pointer+=1 #שמרנו את כל הקלפים שנזרקו בסיבוב בליסט1, ועכשיו בודקים איזה קלף הכי חזק ושומרים את הערכים שלו בשני משתנים וכמובן את השם של המנצח maximumcardvalue=0
def test_init_3( self): #checks the function not insert empty name to player game = CardGame(5) self.assertTrue(game.players[0].name == "Player1")
def test_init_2( self ): #checks the function actually insert numofcards=5 if the user insert something else game = CardGame(6) self.assertTrue(game.numofcards == 5)
def test_cards_per_round3(self): game1 = CardGame(5) game1.players[0].playercards = [] self.assertTrue(game1.CardsPerRound(3) == "False")
def test_cards_per_round2( self ): #checks the function not works with invalid value of pointer game1 = CardGame(5) self.assertTrue(game1.CardsPerRound('fdg') == "False")
def test_cards_per_round( self ): #checks the function not works with negative value of pointer game1 = CardGame(5) self.assertTrue(game1.CardsPerRound(-1) == "False")
def test_pay_round3( self): #checks the function call right the stub function with patch('games.cards.Player.Player.reduceAmount') as mock_a: game1 = CardGame(5) game1.PayRound(2) mock_a.assert_called_with(200)
def test_pay_round2( self): #checks the function not works with invalid round value game1 = CardGame(5) self.assertTrue(game1.PayRound('gfdd') == "False")
def test_pay_round( self): #checks the function not works with negative round value game1 = CardGame(5) self.assertTrue(game1.PayRound(-1) == "False")
def test_new_game2( self ): #checks the function insert cards to player as the number of cards of the game game1 = CardGame(5) game1.newGame() self.assertTrue(len(game1.players[0].playercards) == game1.numofcards)
amount_on_table += 100 * round_game # Collect money from each player on round print("Cards on table: ") lst_cards = list(cards_on_table.items()) round_winner = check_who_won_round(lst_cards) print("\nThe winner in this round is: ") round_winner[0].add_amount(amount_on_table) print(round_winner[0].name, "\n") biggest_amount = 0 the_winner = None for player in card_game.lst_of_players: # Check who is the winner if biggest_amount < player.amount_money: biggest_amount = player.amount_money the_winner = player print("***** THE WINNER IS *****") print(f"""{the_winner.name} with amount of {the_winner.amount_money} """) card_game = CardGame(5) card_game.new_game() type_cards = {"Diamond": 1, "Spade": 2, "Heart": 3, "Club": 4} play_game = "y" while play_game == "y": start_game() play_game = input("\nPlay Again, Insert Y else game will stop: ").lower() if play_game == "y": card_game.new_game()
def setUp(self): self.card_game = CardGame()