def test_sort_cards_by_default_value(): deck = Deck() deck.cards = [Card("red", 7), Card("red", 0), Card("red", 3), Card("yellow", 2), Card("yellow", 1), Card("green", 8)] deck.sort() correct_order = [("red", 0), ("red", 3), ("red", 7), ("yellow", 1), ("yellow", 2), ("green", 8)] sorted_cards = [(card.color, card.rank) for card in deck.cards] assert (correct_order == sorted_cards)
def test_construction(): deck = Deck() assert len(deck.cards) == 3 * 10 # 3 colors ranked 0-9
def test_sort_cards_raises_error_on_invalid_color_list(): deck = Deck() with pytest.raises(ValueError): deck.sort(["purple"])
def test_end_of_deck(): deck = Deck() for _ in range(30): deck.draw() with pytest.raises(EndOfDeckError): deck.draw()
def test_draw_card(): deck = Deck() card = deck.draw() assert (type(card).__name__ == "Card") assert (len(deck.cards) == 29) assert (card not in deck.cards)
def test_shuffle(): deck = Deck() old_order = [card for card in deck.cards] deck.shuffle() assert deck.cards != old_order
import sys import os path = os.path.join(os.path.dirname(__file__), '..') sys.path.extend([path]) from deck_of_cards.card import Card from deck_of_cards.deck import Deck #trying card combinations # c = Card('A', 'Spades') # c1 = Card('K', 'Hearts') # c2 = Card('3', 'Diamonds') # c3 = Card('10', 'Hearts') # print(c, c1, c2, c3) d = Deck() print(d) print(d.deal_hand(2)) print('return from count function after deal_hand: ', d.count()) print(d.deal_card()) print('return from count function after deal_card: ', d.count()) print(d.shuffle())