Example #1
0
def test_deck_draw_card_all_cards_are_different():
    deck = Deck()
    deck.fill_deck_with_52_cards()
    drawn_cards = set()

    for _ in range(52):
        card = deck.draw_card()
        assert card not in drawn_cards
        drawn_cards.add(card)

    assert len(drawn_cards) == 52
Example #2
0
def test_deck_shuffle():  # This will fail with a probability of 1/52
    deck = Deck()
    deck.reset_deck_and_shuffle()
    card_a = deck.draw_card()

    deck.reset_deck_and_shuffle()
    card_b = deck.draw_card()

    assert card_a != card_b
Example #3
0
def test_deck_shuffle_does_not_give_same_card():
    deck = Deck()
    deck.reset_deck_and_shuffle()
    card_a = deck.draw_card()

    deck.reset_deck_and_shuffle()
    card_b = deck.draw_card()

    assert card_a != card_b
Example #4
0
def test_deck_draw_more_than_52_raises_NoMoreCardsInDeckError():
    deck = Deck()
    deck.fill_deck_with_52_cards()

    # Draw all cards from deck
    for _ in range(52):
        deck.draw_card()

    try:  # draw one too many
        deck.draw_card()
    except NoMoreCardsInDeckError:
        return  # Test complete

    raise Exception("F**K YOU! THIS SHOULD'NT HAVE HAPPENED")
Example #5
0
def test_cannot_take_same_card_twice():
    deck = Deck()
    assert len(deck) == 0

    deck.take_card(Card(Suites.HEARTS, 9))
    assert len(deck) == 1

    try:
        deck.take_card(Card(Suites.HEARTS, 9))
        raise Exception("Should not reach here")
    except CardAlreadyInDeckError:
        pass

    assert len(deck) == 1
Example #6
0
def test_take_card_puts_on_bottom_of_the_deck_when_lifo_false():
    deck = Deck()
    assert len(deck) == 0

    card_a = Card(Suites.HEARTS, 9)
    card_b = Card(Suites.SPADES, 7)

    deck.take_card(card_a, top_of_deck=False)
    deck.take_card(card_b, top_of_deck=False)

    assert deck.draw_card() == card_a
    assert len(deck) == 1

    assert deck.draw_card() == card_b
    assert len(deck) == 0
Example #7
0
def test_take_card_puts_on_top_of_the_deck():
    deck = Deck()
    assert len(deck) == 0

    card_a = Card(Suites.HEARTS, 9)
    card_b = Card(Suites.SPADES, 7)

    deck.take_card(card_a)
    deck.take_card(card_b)

    assert deck.draw_card() == card_b
    assert len(deck) == 1

    assert deck.draw_card() == card_a
    assert len(deck) == 0
Example #8
0
def test_deck_equals():
    deck_a = Deck()
    deck_b = Deck()
    assert deck_a == deck_b