def test_no_name_input(self): """בודקת האם המשחק עובד כאשר לא מזינים בכלל פרטים. לא כמות קלפים לחלוקה ולא שמות שחקנים""" self.game_test = CardGame() self.assertEqual(self.game_test.player_1.name, "player-1") self.assertEqual(self.game_test.player_2.name, "player-2") self.assertEqual(self.game_test.player_1.num_cards, 10) self.assertEqual(self.game_test.player_2.num_cards, 10)
def test_new_game_deck_not_full(self): """checks the function wont start a new game if the deck is not full""" cardgame = CardGame('ohad', 'polly') self.assertEqual(len(cardgame.player1.player_hand), 10) self.assertEqual(len(cardgame.player2.player_hand), 10) self.assertEqual(len(cardgame.deck.list_cards), 32) cardgame.new_game() self.assertNotEqual(len(cardgame.deck.list_cards), 52)
def test_get_winner_draw(self): """checks if the result is draw""" player1 = Player("ohad") player2 = Player("polly") game = CardGame(player1.name, player2.name) game.player2.player_hand = [Card(8, 3), Card(9, 4), Card(13, 4)] game.player1.player_hand = [Card(7, 3), Card(10, 4), Card(12, 4)] winner = game.get_winner() self.assertEqual(None, winner)
def test_get_winner_player1_win(self): """checks thw winner is player 1""" player1 = Player("ohad") player2 = Player("polly") game = CardGame(player1.name, player2.name) game.player2.player_hand = [Card(8, 3), Card(9, 4), Card(13, 4)] game.player1.player_hand = [Card(7, 3)] winner = game.get_winner() self.assertEqual(player1.name, winner)
def setUp(self): self.game_test = CardGame("dima", "shachar")
def test_new_game_minus(self): """בודקת שמחזירה שגיאה כאשר מספר הקלפים לחלוקה הוא מינוס""" with self.assertRaises(SystemExit): self.game_test = CardGame("dima", "shachar", -5)
class TestCardGame(TestCase): def setUp(self): self.game_test = CardGame("dima", "shachar") def test_num_cards_not_int(self): """בודקת שהמערכת מציגה שגיאה כאשר כמות הקלפים לחלוקה אינו מספר תקין""" with self.assertRaises(SystemExit): self.game_test = CardGame("dima", "shachar", "bdika") def test_no_name_input(self): """בודקת האם המשחק עובד כאשר לא מזינים בכלל פרטים. לא כמות קלפים לחלוקה ולא שמות שחקנים""" self.game_test = CardGame() self.assertEqual(self.game_test.player_1.name, "player-1") self.assertEqual(self.game_test.player_2.name, "player-2") self.assertEqual(self.game_test.player_1.num_cards, 10) self.assertEqual(self.game_test.player_2.num_cards, 10) def test_get_winner(self): """בודקת כאשר יש לשחקן השני פחות קלפים שהשם שלו חוזר""" card1 = Card(1, 1) card2 = Card(2, 2) card3 = Card(3, 3) self.game_test.player_1.player_deck = [card1, card2] self.game_test.player_2.player_deck = [card3] self.assertIn("shachar", self.game_test.get_winner()) # self.assertIn(self.game_test.player_2.name, self.game_test.get_winner()) def test_get_winner_none(self): """בודקת במידה והרשימות של שני השחקנים באותו אורך שהיא מחזירה none""" card1 = Card(1, 1) card2 = Card(2, 2) card3 = Card(5, 2) card4 = Card(7, 4) self.game_test.player_1.player_deck = [card1, card2] self.game_test.player_2.player_deck = [card3, card4] self.assertIsNone(self.game_test.get_winner()) def test_new_game(self): """בודקת שבמידה והפונקציה לא הופעלה מהקונסטרקטור היא מחזירה שגיאה""" with self.assertRaises(SystemExit): self.game_test.new_game() def test_new_game_20(self): """בודקת שבאמת מחלקת את כמות הקלפים שהמשתמש ביקש""" self.game_test = CardGame("dima", "shachar", 20) self.assertEqual(len(self.game_test.player_1.player_deck), 20) self.assertEqual(len(self.game_test.player_2.player_deck), 20) def test_new_game_0(self): """בודקת שמחזירה שגיאה כאשר מספר הקלפים לחלוקה הוא 0""" with self.assertRaises(SystemExit): self.game_test = CardGame("dima", "shachar", 0) def test_new_game_minus(self): """בודקת שמחזירה שגיאה כאשר מספר הקלפים לחלוקה הוא מינוס""" with self.assertRaises(SystemExit): self.game_test = CardGame("dima", "shachar", -5) def test_new_game_30(self): """בודקת מה קורה אם הזנו מעל 26 קלפים לכל אחד""" self.game_test = CardGame("dima", "shachar", 30) self.assertEqual(len(self.game_test.player_1.player_deck), 26)
def test_new_game_20(self): """בודקת שבאמת מחלקת את כמות הקלפים שהמשתמש ביקש""" self.game_test = CardGame("dima", "shachar", 20) self.assertEqual(len(self.game_test.player_1.player_deck), 20) self.assertEqual(len(self.game_test.player_2.player_deck), 20)
class TestCardGame(TestCase): def setUp(self): print("Set_up") self.my_game = CardGame(5) self.my_game.new_game_n() def tearDown(self): print("Tear_down") def test_create_players_1(self): # check that "create_players" create 4 players self.my_game.create_players(5000) self.assertTrue(4, len(self.my_game.players)) def test_reduce_players_money_1(self): # check money after "reduce_players_money" in player 1 in game found 1 (the difference is 100) before_money = self.my_game.players[0].money self.my_game.reduce_players_money(1) after_money = self.my_game.players[0].money self.assertEqual(before_money, after_money + 100) def test_reduce_players_money_2(self): # check money after "reduce_players_money" in player 1 in game found 3 (the difference is 300) before_money = self.my_game.players[0].money self.my_game.reduce_players_money(3) after_money = self.my_game.players[0].money self.assertEqual(before_money, after_money + 300) def test_reduce_players_money_3(self): # check money after "reduce_players_money" in player 2 in game found 1 (the difference is 100) before_money = self.my_game.players[1].money self.my_game.reduce_players_money(1) after_money = self.my_game.players[1].money self.assertEqual(before_money, after_money + 100) def test_reduce_players_money_4(self): # check money after "reduce_players_money" in player 2 in game found 3 (the difference is 300) before_money = self.my_game.players[1].money self.my_game.reduce_players_money(3) after_money = self.my_game.players[1].money self.assertEqual(before_money, after_money + 300) def test_get_cards(self): # check "get_cards" list_test = self.my_game.get_move_cards() print(list_test) self.assertEqual(len(list_test), 4) def test_compare_cards_1(self): # check "compare_cards" to 4 cards in list (check value). self.c1 = Card(5, "Heart") self.c2 = Card(1, "Spade") self.c3 = Card(12, "Heart") self.c4 = Card(13, "Club") temp_list = [self.c1, self.c2, self.c3, self.c4] self.assertEqual(self.my_game.compare_cards(temp_list), self.c4) def test_compare_cards_2(self): # check "compare_cards" to 4 cards in list (check suit). self.c1 = Card(13, "Heart") self.c2 = Card(13, "Spade") self.c3 = Card(13, "Heart") self.c4 = Card(13, "Club") temp_list = [self.c1, self.c2, self.c3, self.c4] self.assertEqual(self.my_game.compare_cards(temp_list), self.c4) def test_compare_cards_3(self): # check "compare_cards" to 4 cards in list. self.c1 = Card(13, "Heart") self.c2 = Card(13, "Spade") self.c3 = Card(13, "Heart") self.c4 = Card(13, "Club") temp_list = [self.c1, self.c2, self.c3, self.c4] self.assertEqual(self.my_game.compare_cards(temp_list), self.c4) def test_win(self): # check that "win" return 4 player. self.assertEqual(len(self.my_game.win()[0]), 4)
def test_new_game_checking(self): """checking the function is really gives cards to the players""" cg = CardGame('ohad', 'polly') self.assertEqual(len(cg.player1.player_hand), 10) self.assertEqual(len(cg.player2.player_hand), 10)
def test_card_num__init__(self): """checks card number will be 10 as default""" cg = CardGame("aa", "bb") self.assertEqual(cg.num_cards, 10)
from games_cards.CardGame import CardGame play1 = CardGame("dima", "shachar") print(play1.player_1.show()) print(play1.player_2.show()) print("=====================") count = 0 for i in range(1, 11): count += 1 # count בודקת לנו האם המשחק רץ לפחות סיבוב אחד print(f"round {i}!!!") card1 = play1.player_1.get_card() # שולפת קלף משחקן ראשון print(f"card of {play1.player_1.name}: {card1}") card2 = play1.player_2.get_card() # שולפת קלף משחקן שני print(f"card of {play1.player_2.name}: {card2}") if card1 > card2: # בודקת מי המנצח בסיבוב הנוכחי play1.player_2.add_card(card1) play1.player_2.add_card(card2) print(f"the winner is {play1.player_1.name}") else: play1.player_1.add_card(card1) play1.player_1.add_card(card2) print(f"the winner is {play1.player_2.name}") print(play1.player_1.show()) print(play1.player_2.show()) print("=====================") if len(play1.player_1.player_deck) == 0 or len( play1.player_2.player_deck) == 0: # אם לאחד מהשחקנים נגמר הקלפים המשחק נגמר והוא המנצח print("\ngame over") break
from games_cards.DeckOfCards import DeckOfCards from games_cards.Player import Player from games_cards.CardGame import CardGame # d = DeckOfCards() # my_game = CardGame(5) # my_game.new_game() # print(my_game) # for i in range(5): # for player in my_game.players: # player.reduce_amount(100 * i) # pack = [] # suits = ["Diamond", "Spade", "Heart", "Club"] # for suit in suits: # for num in range(1, 14): # c = Card(num, suit) # pack.append(c) # # print(pack) # # p = pack[1] # print(p.value) my_game = CardGame(5) my_game.new_game_n() for i in range(1, 5): my_game.game_move(i) print(f"the whiner are- {my_game.win()[0]} with {my_game.win()[1]} dollars")
def setUp(self): print("Set_up") self.my_game = CardGame(5) self.my_game.new_game_n()
def test_new_game_30(self): """בודקת מה קורה אם הזנו מעל 26 קלפים לכל אחד""" self.game_test = CardGame("dima", "shachar", 30) self.assertEqual(len(self.game_test.player_1.player_deck), 26)
def test_num_cards_not_int(self): """בודקת שהמערכת מציגה שגיאה כאשר כמות הקלפים לחלוקה אינו מספר תקין""" with self.assertRaises(SystemExit): self.game_test = CardGame("dima", "shachar", "bdika")
from games_cards.CardGame import CardGame from games_cards.Player import Player player1 = Player(input("enter player 1 name,(name must be letters only): ")) player2 = Player(input("enter player 2 name,(name must be letters only): ")) game = CardGame(player1.name, player2.name) print(game.player1.show()) print(game.player2.show()) for i in range(10): print(f"Round {i+1}") a = (game.player1.get_card()) b = (game.player2.get_card()) print(a) print(b) if a > b: game.player2.add_card(b) game.player2.add_card(a) print(f"the winner is {player1.name}") if a < b: game.player1.add_card(b) game.player1.add_card(a) print(f"the winner is {player2.name}") print(f" The winner of the game is : {game.get_winner()}")