コード例 #1
0
    def test_dealOneCard_whenCalledBeforeShuffle_returnsAceCardAsDeckConfiguredAceHigh(self):
        deck = PokerDeck.create()

        card = deck.dealOneCard()

        # by default cards are ordered asc so smallest cards are at the bottom
        # this is definitely an implementation detail that could be interpreted differently
        # if we wanted to have the "2" at the top, would change the Deck's init to sort descending then update this test
        assert card and card.id == "A"
コード例 #2
0
    def test_shuffle_whenNoCards_thenNoError(self):
        deck = PokerDeck.create()

        # deal all cards
        while deck.cardsRemaining():
            deck.dealOneCard()

        deck.shuffle()

        assert True
コード例 #3
0
    def test_create_whenCalled_thenCardsOrderedAscending(self):
        deck = PokerDeck.create()

        orderedCorrectly = True
        for i in range(1, len(deck._cards)): # start at index 1 to guarantee (i-1) in bounds
            if deck._cards[i - 1].order > deck._cards[i].order:
                orderedCorrectly = False
                break

        assert orderedCorrectly
コード例 #4
0
    def test_dealOneCard_whenDeckIsEmpty_thenNoCardDealt(self):
        deck = PokerDeck.create()
        deck.shuffle()

        # deal all cards
        while deck.cardsRemaining() > 0:
            deck.dealOneCard()

        # deck is now empty
        card = deck.dealOneCard()

        assert card is None
コード例 #5
0
    def test_shuffle_whenTwoCards_thenSwapped(self):
        deck = PokerDeck.create()

        numCards = deck.cardsRemaining()
        for _ in range(numCards - 2):
            deck.dealOneCard()

        preShuffleCards = deck._cards[:] # shallow copy

        deck.shuffle()

        assert preShuffleCards[0].id == deck._cards[1].id
        assert preShuffleCards[1].id == deck._cards[0].id
コード例 #6
0
    def test_shuffle_whenFullDeck_thenSuccess(self):
        deck = PokerDeck.create()

        preShuffleCards = deck._cards[:] # shallow copy

        deck.shuffle()

        atLeastOneCardPositionChanged = False
        for i in range(deck._initCardCount):
            if preShuffleCards[i].id != deck._cards[i].id:
                atLeastOneCardPositionChanged = True
                break

        assert atLeastOneCardPositionChanged
コード例 #7
0
    def test_create_whenCalled_thenFiftyTwoCardsCreatedSuccessfully(self):
        deck = PokerDeck.create()

        heartUniqueSeen = set()
        spadeUniqueSeen = set()
        clubUniqueSeen = set()
        diamondUniqueSeen = set()

        for card in deck._cards:
            if card.suit == Suit.HEART: heartUniqueSeen.add(card.id)
            if card.suit == Suit.SPADE: spadeUniqueSeen.add(card.id)
            if card.suit == Suit.CLUB: clubUniqueSeen.add(card.id)
            if card.suit == Suit.DIAMOND: diamondUniqueSeen.add(card.id)

        assert len(heartUniqueSeen) == 13
        assert len(spadeUniqueSeen) == 13
        assert len(clubUniqueSeen) == 13
        assert len(diamondUniqueSeen) == 13
コード例 #8
0
 def test_dealOneCard_whenCalledBeforeShuffle_returnsKingCardAsDeckConfiguredAceLow(self):
     deck = PokerDeck.create({"ace_high": False})
     card = deck.dealOneCard()
     assert card and card.id == "K"
コード例 #9
0
 def test_init_whenCardsProvided_thenSetProperly(self):
     cards = []
     cards.append(PokerCard('2', 'Two', Suit.HEART, 2))
     cards.append(PokerCard('3', 'Three', Suit.HEART, 3))
     deck = PokerDeck(cards)
     assert len(deck._cards) == 2
コード例 #10
0
 def test_isEmpty_whenFiftyTwoDealt_thenReturnTrue(self):
     deck = PokerDeck.create()
     for _ in range(52):
         deck.dealOneCard()
     assert deck.isEmpty() == True
コード例 #11
0
 def test_isEmpty_whenOneDealt_thenReturnFalse(self):
     deck = PokerDeck.create()
     deck.dealOneCard()
     assert deck.isEmpty() == False
コード例 #12
0
 def test_cardsRemaining_whenOneDealt_thenReturnFiftyOne(self):
     deck = PokerDeck.create()
     deck.dealOneCard()
     assert deck.cardsRemaining() == 51
コード例 #13
0
 def test_cardsRemaining_whenNoneDealt_thenReturnFiftyTwo(self):
     deck = PokerDeck.create()
     assert deck.cardsRemaining() == 52
コード例 #14
0
 def test_cardsDealt_whenOneDealt_thenReturnOne(self):
     deck = PokerDeck.create()
     deck.dealOneCard()
     assert deck.cardsDealt() == 1
コード例 #15
0
 def test_init_whenCalled_thenDeckTypeIsPoker(self):
     deck = PokerDeck([])
     assert deck.deckType == DeckType.POKER
コード例 #16
0
 def test_cardsDealt_whenNone_thenReturnZero(self):
     deck = PokerDeck.create()
     assert deck.cardsDealt() == 0