def test_deck(): # Test that all cards are in the deck deck_1 = cardlib.StandardDeck() deck_1.create_deck() assert len(deck_1) == 52 # Test the shuffle function deck_2 = cardlib.StandardDeck() deck_2.create_deck() deck_2.shuffle() assert deck_2 != deck_1 # Test the draw function drawn_cards = deck_1.draw_card(5) assert drawn_cards[0] == num_card( 2, suit.clubs) and drawn_cards[4] == num_card(3, suit.clubs) assert len(deck_1) < 52 assert drawn_cards[0] not in deck_1
def test_add_new_card_adds_correct_card_from_source(): deck = cardlib.StandardDeck() hand = cardlib.Hand() deck_top_card = deck.cards[0] # copy topcard of deck hand.add_new_card(deck.deal_top_card()) # deal top card to hand assert hand.cards[0] == deck_top_card # Check that the previous topcard is discarded assert deck.cards[0] != deck_top_card
def test_add_drop_cards(): deck = cardlib.StandardDeck() test_deck1 = [card.get_value() for card in deck.cards] deck.shuffledeck() test_deck2 = [card.get_value() for card in deck.cards] assert deck.cards != [] assert test_deck1 != test_deck2 # Tests shuffle function test_hand = cardlib.Hand() test_hand.add(deck.drawfromdeck()) test_hand.add(deck.drawfromdeck()) assert len(test_hand.cards) == 2 test_hand.drop([0]) assert len(test_hand.cards) == 1
def start(self): ''' set/reset playvalues before/between rounds ''' self.running = True self.bet_pot.clear() self.call_count = 0 self.deck = cl.StandardDeck(2) self.deck.shuffle() self.players[0].set_active(True) self.last_bets = [] # Deal cards: for i in range(2): self.players[0].hand.add_card(self.deck.deal_top_card()) self.players[1].hand.add_card(self.deck.deal_top_card())
def test_best_poker_hand(): deck_1 = cardlib.StandardDeck() deck_1.create_deck() card_1 = num_card(9, suit.spades) card_2 = ace_card(suit.hearts) player_1_cards = cardlib.Hand() player_1_cards.add_card(card_1) player_1_cards.add_card(card_2) # High card community_cards = [(num_card(1, suit.diamonds)), (num_card(8, suit.spades)), (num_card(3, suit.spades)), (num_card(4, suit.clubs)), (num_card(5, suit.spades))] check_high_card = player_1_cards.best_poker_hand(community_cards) assert check_high_card == [card_2] # One pair community_cards = [(num_card(3, suit.diamonds)), (num_card(8, suit.spades)), (num_card(3, suit.spades)), (num_card(4, suit.clubs)), (num_card(5, suit.spades))] check_one_pair = player_1_cards.best_poker_hand(community_cards) assert check_one_pair == [ num_card(3, suit.spades), num_card(3, suit.diamonds) ] # Two pairs community_cards = [(num_card(3, suit.diamonds)), (num_card(8, suit.spades)), (num_card(3, suit.spades)), (num_card(4, suit.clubs)), (ace_card(suit.spades))] check_two_pairs = player_1_cards.best_poker_hand(community_cards) assert check_two_pairs == [ ace_card(suit.hearts), ace_card(suit.spades), num_card(3, suit.spades), num_card(3, suit.diamonds) ] # Three of a kind community_cards = [(num_card(3, suit.diamonds)), (num_card(3, suit.clubs)), (num_card(3, suit.spades)), (num_card(4, suit.clubs)), (num_card(2, suit.spades))] check_three_of_a_kind = player_1_cards.best_poker_hand(community_cards) assert check_three_of_a_kind == [(num_card(3, suit.spades)), (num_card(3, suit.diamonds)), (num_card(3, suit.clubs))] # Straight community_cards = [(num_card(7, suit.diamonds)), (num_card(5, suit.clubs)), (num_card(8, suit.spades)), (num_card(6, suit.clubs)), (num_card(2, suit.spades))] check_straight = player_1_cards.best_poker_hand(community_cards) assert check_straight == [(num_card(9, suit.spades))] # Flush community_cards = [(num_card(3, suit.hearts)), (num_card(3, suit.hearts)), (num_card(3, suit.hearts)), (num_card(4, suit.hearts)), (num_card(2, suit.spades))] check_flush = player_1_cards.best_poker_hand(community_cards) assert check_flush == [(ace_card(suit.hearts)), (num_card(4, suit.hearts)), (num_card(3, suit.hearts)), (num_card(3, suit.hearts)), (num_card(3, suit.hearts))] # Full house community_cards = [(ace_card(suit.diamonds)), (num_card(3, suit.clubs)), (num_card(3, suit.spades)), (num_card(3, suit.clubs)), (num_card(2, suit.spades))] check_full_house = player_1_cards.best_poker_hand(community_cards) assert check_full_house == [(num_card(3, suit.spades)), (num_card(3, suit.clubs)), (num_card(3, suit.clubs)), (ace_card(suit.hearts)), (ace_card(suit.diamonds))] # Four of a kind community_cards = [(num_card(3, suit.diamonds)), (num_card(3, suit.clubs)), (num_card(3, suit.spades)), (num_card(3, suit.hearts)), (num_card(2, suit.spades))] check_four_of_a_kind = player_1_cards.best_poker_hand(community_cards) assert check_four_of_a_kind == [(num_card(3, suit.hearts)), (num_card(3, suit.spades)), (num_card(3, suit.diamonds)), (num_card(3, suit.clubs))] # Straight flush community_cards = [(king_card(suit.hearts)), (jack_card(suit.hearts)), (queen_card(suit.hearts)), (num_card(10, suit.hearts)), (num_card(2, suit.spades))] check_straight_flush = player_1_cards.best_poker_hand(community_cards) assert check_straight_flush == [(ace_card(suit.hearts))]
def test_deck_contains_correct_number_of_correct_cards(): deck = cardlib.StandardDeck() assert len(np.unique(deck.cards)) == 52
def test_deck_is_correct_size(): deck = cardlib.StandardDeck(1) assert len(deck.cards) == 52