def test_card_score(): green_card = Card("green", 5) yellow_card = Card("yellow", 4) red_card = Card("red", 8) assert (green_card.score() == 5) # 1 * 5 assert (yellow_card.score() == 8) # 2 * 4 assert (red_card.score() == 24) # 3 * 8
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 __init__(self): suites = ['Hearts', 'Diamonds', 'Spades', 'Clubs'] values = [ 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K' ] self.cards = [Card(value, suit) for suit in suites for value in values]
def __init__(self): colors = ["red", "yellow", "green"] self.cards = [ Card(color, rank) for color in colors for rank in range(0, 10) ] self.shuffle()
def test_card_properties(): card = Card("red", 7) assert (card.color == "red") assert (card.rank == 7)
def test_valid_input_for_card_creation(): with pytest.raises(ValueError): Card("purple", 7) with pytest.raises(ValueError): Card("red", 17)