def test_shuffle(): """ Checks decks are shuffled and no longer equal may fail VERY rarely, but shouldn't in my lifetime """ deck = fours.Deck() deck2 = fours.Deck() deck.shuffle() deck2.shuffle() assert_that(deck).is_not_equal_to(deck2)
def test_out(): """ Checks that when out of cards it raises the correct exception """ deck = fours.Deck() for _ in range(52): deck.draw() assert_that(deck.draw).raises(fours.OutOfCards).when_called_with()
def test_duplicates(): """ check a deck of cards has no duplicates, even when converted to a string """ deck = fours.Deck() assert_that(len(set(deck.cards))).is_equal_to(len(deck.cards)) assert_that(len({x.__repr__() for x in deck.cards}))\ .is_equal_to(len([x.__repr__() for x in deck.cards]))
def test_cards(): """ Checks that there are 52 cards in a deck, each with a valid value and suit """ deck = fours.Deck() for _ in range(52): card = deck.draw() assert_that(card.suit).is_in("Hearts", "Clubs", "Diamonds", "Spades") assert_that(card.value).is_in(*range(13))
def test_draw(): """ Tests that a non shuffled deck always gives the same board state """ not_shuffled = fours.Deck() game = fours.Fours() game.deck = not_shuffled game.draw_card() assert_that(game.board).is_equal_to([[fours.Card("Spades", 12)], [fours.Card("Spades", 11)], [fours.Card("Spades", 10)], [fours.Card("Spades", 9)]])
def test_size(): """ Checks a deck has 52 cards """ deck = fours.Deck() assert_that(deck.cards).is_length(52)