class TestDeckOfCards(TestCase): def setUp(self): self.deck_cards = DeckOfCards() self.deck_shuffle = DeckOfCards() def test_nums_of_card_in_deck(self): self.assertEqual(len(self.deck_cards.deck), 52) def test_deal_one(self): top_card_on_deck = self.deck_cards.deal_one() self.assertEqual(str(top_card_on_deck), "2 of Diamond") def test_new_game(self): self.deck_shuffle.new_game() # New game will shuffle the deck self.assertTrue(self.deck_cards.deck != self.deck_shuffle.deck) # Not the same order in deck @mock.patch('builtins.print') def test_show(self, mock_print): self.deck_cards.show() results_expected = "" for card in self.deck_cards.deck: results_expected += str(card) + "\n" mock_print.assert_called_with(results_expected)
def test_new_game2( self): #checks that the function not works with unfull list deck1 = DeckOfCards() deck1.listcards.pop() deck2 = deck1.listcards.copy() deck1.newGame() self.assertTrue(deck1.listcards[0] == deck2[0])
def test_deal_one1( self): #checks that function not works with over than full list deck1 = DeckOfCards() deck1.listcards = [] for i in range(53): card1 = Card(i + 1, "Heart") deck1.listcards.append(card1) self.assertTrue(deck1.dealOne() != True)
def test_deal_one(self): #checks that function not works with empty list # with patch ('games.cards.DeckOfCards.DeckOfCards.dealOne') as mock_dealone: # mock_dealone.return_value = 5 # deck1 = DeckOfCards() # self.assertTrue(deck1.dealOne(),5) deck1 = DeckOfCards() deck1.listcards = [] self.assertFalse(deck1.dealOne())
def test_shuffle(self): deck1 = DeckOfCards() deck2 = deck1.listcards.copy() deck1.newGame() break1 = 0 for i in range(len(deck1.listcards)): if deck1.listcards[i] != deck2[i]: break1 += 1 break self.assertTrue(break1 == 1)
def test_deal_one2( self ): #checks that function not work with value that isn't type 'Card' deck1 = DeckOfCards() deck1.listcards = [] for i in range(50): card1 = Card(i + 1, "Heart") deck1.listcards.append(card1) deck1.listcards.append(4) self.assertFalse(deck1.dealOne())
def test_new_game( self): #checks that the function suffle the valid list (52 values) deck1 = DeckOfCards() deck2 = deck1.listcards.copy() deck1.newGame() break1 = 0 for i in range(len(deck1.listcards)): if deck1.listcards[i] != deck2[i]: break1 += 1 break self.assertTrue(break1 == 1)
def test_deal_one3(self): #checks that the function works with valid list deck1 = DeckOfCards() deck1.listcards = [] for i in range(50): card1 = Card(1, "Heart") deck1.listcards.append(card1) length = len(deck1.listcards) print(length) deck1.dealOne() print(len(deck1.listcards)) self.assertTrue(len(deck1.listcards) == length - 1)
def __init__(self, num_of_cards=5): DeckOfCards.__init__(self) amount_player = random.randint( 5000, 10000) # Random amount between 5000-10000 self.num_of_cards = num_of_cards self.lst_of_players = \ [ Player("Richard", amount_player, num_of_cards), Player("Ricky", amount_player, num_of_cards), Player("Shay", amount_player, num_of_cards), Player("Ori", amount_player, num_of_cards) ]
def __init__(self, numofcards): self.listofcards = DeckOfCards().listcards self.numofcards = numofcards if type(numofcards) != int: raise ValueError("inalid numofcards type.") if self.numofcards > 5 or self.numofcards < 0: self.numofcards = 5 self.players = [] for i in range(0, 4, 1): player = Player(input("enter name of player"), input("enter amount of money")) if player.name == "": player.name = "Player" + str(i + 1) if player.money < 5000 or player.money > 10000: player.money = 5000 self.players.append(player)
class CardGame: #פונקציית אתחול של משחק חדש def __init__(self, numofcards): self.listofcards = DeckOfCards().listcards self.numofcards = numofcards if type(numofcards) != int: raise ValueError("inalid numofcards type.") if self.numofcards > 5 or self.numofcards < 0: self.numofcards = 5 self.players = [] for i in range(0, 4, 1): player = Player(input("enter name of player"), input("enter amount of money")) if player.name == "": player.name = "Player" + str(i + 1) if player.money < 5000 or player.money > 10000: player.money = 5000 self.players.append(player) #פונקציה שמתחילה משחק- מערבבת את חפיסת הקלפים ומחלקת קלפים לכל שחקן במשחק def newGame(self): shuffle(self.listofcards) for i in range(0, len(self.players), 1): for n in range(0, self.numofcards, 1): self.players[i].addCard(self.listofcards.pop()) #פונקציה שמקבלת מספר סיבוב ומחשבת ומחזירה את הפרס הכספי לאותו הסיבוב ע"י החסרה של כסף מכל אחד מהמשתתפים def PayRound(self, round): if type(round) != int: return "False" elif round < 0: return "False" else: sum = 0 for i in self.players: i.reduceAmount(100 * round) sum += 100 * round return sum #פונקציה המקבלת מצביע ברשימת השחקנים במשחק, שולפת את הקלף האחרון בחפיסה שלו וכן מחזירה אותו def CardsPerRound(self, pointer): if type(pointer) != int: return "False" if pointer < 0: return "False" elif len(self.players[pointer].playercards) == 0: return "False" else: return self.players[pointer].playercards.pop()
def test_show(self): #checks the function not work with invalid values deck1 = DeckOfCards() deck1.listcards = [] deck1.listcards.append(5) self.assertTrue(deck1.show() == "False")
def setUp(self): self.deck_cards = DeckOfCards() self.deck_shuffle = DeckOfCards()