def test_sort_all_card(sorted_ranks): sorted_deck = main.Deck() sorted_cards = [ main.Card(suit, rank) for suit in main.Suit for rank in sorted_ranks ] sorted_deck.cards = sorted_cards deck = main.Deck() deck.sort([ main.Suit.Spades, main.Suit.Diamonds, main.Suit.Hearts, main.Suit.Clubs ]) deck.print() assert sorted_deck == deck, "test sort all cards failed"
def test_sort_example_failed(): deck = main.Deck() result_deck = main.Deck() deck.cards = [ main.Card(main.Suit.Spades, main.Rank._2), main.Card(main.Suit.Diamonds, main.Rank._5), main.Card(main.Suit.Spades, main.Rank.King), main.Card(main.Suit.Hearts, main.Rank._3), main.Card(main.Suit.Clubs, main.Rank.Ace) ] deck.sort([ main.Suit.Spades, main.Suit.Diamonds, main.Suit.Hearts, main.Suit.Clubs ]) result_deck.cards = [ main.Card(main.Suit.Spades, main.Rank._2), main.Card(main.Suit.Diamonds, main.Rank._5), main.Card(main.Suit.Spades, main.Rank.King), main.Card(main.Suit.Hearts, main.Rank._3), main.Card(main.Suit.Clubs, main.Rank.Ace) ] assert result_deck != deck, "test sort example failed"
def test_sort_empty(): deck = main.Deck() deck.sort([]) assert len(deck.cards) == 0, "test not empty deck failed"
def test_exception_on_empty_deck(): with pytest.raises(TypeError, match="There is no card left in the deck"): deck = main.Deck() for _ in range(53): deck.get_card()
def test_get_card_no_top(): deck = main.Deck() card = deck.cards[0] top_card = deck.get_card() assert card != top_card, "test no top card failed"
def test_no_shuffle(): deck = main.Deck() deckShuffle = main.Deck() assert deck == deckShuffle, "test no shuffle failed"
def test_get_card(): deck = main.Deck() card = deck.cards[-1] top_card = deck.get_card() assert card == top_card, "test top card failed"
def test_suits(): deck = main.Deck()
def test_shuffle(): deck = main.Deck() deckShuffle = main.Deck() deckShuffle.shuffle() assert deck != deckShuffle, "test shuffle failed"
def test_rest_deck(): deck = main.Deck() deck.mix_deck() deck.hand_cards() assert len(deck._ls_mix_deck) == 24
def test_deck(): deck = main.Deck() assert len(deck.all_deck) == 36
def test_computer(): deck = main.Deck() deck.mix_deck() deck.hand_cards() assert len(deck._computer_hand) == 6
def test_player(): deck = main.Deck() deck.mix_deck() deck.hand_cards() assert len(deck.player_hand) == 6
def setUp(self): self.hand = main.Hand() self.hand.hand = [main.Card('2', '♠'), main.Card('3', '♠'), main.Card('4', '♠')] self.deck = main.Deck()
class TestDeck(unittest.TestCase): deck = main.Deck() def test_draw_returns_card(self): self.assertIsInstance(self.deck.draw(), main.Card)
import main print("Welcome to BlackJack") replay = False game_on = True starting_money = main.Account(1000) deck = main.Deck() deck.shuffle() bob = main.Player("Bob") dealer = main.Player("Dealer") bet = False #card = main.Card(bob.hand) while game_on == True or replay == True: bet = False if replay == True: deck = main.Deck() deck.shuffle() bob.hand = [] dealer.hand = [] while bet == False: global amount amount = input("Please state your bet: ") try: starting_money.bet(int(amount)) starting_money.displayBalance() if int(amount) <= starting_money.balance: bet = True except: