Exemple #1
0
    def test_hand(self):
        x = Hand()
        base_deck = Deck()

        #case 1:  add some cards, make sure the hand goes to the right length
        x.add_cards([2, 3, 4, 5], base_deck)
        self.assertTrue(len(x) == 4)

        #case 2:  add some illegal cards, make sure they are not added
        x.add_cards([-1, 55, 'q'], base_deck)
        self.assertTrue(len(x) == 4)

        #case 4: add an initialized card object
        base_deck.reset()
        c1 = Card('As')
        x.add_cards([c1], base_deck)
        self.assertTrue(len(x) == 5)

        #case 5: test adding cards with string names
        base_deck.reset()
        y = Hand()
        y.add_cards(['Ah', 'As', '5d'], base_deck)
        self.assertTrue(len(y) == 3)

        #case 6: insure duplicate strings don't add
        y.add_cards(['Ah'], base_deck)
        self.assertTrue(len(y) == 3)

        #case 7: add from a string
        base_deck.reset()
        y = Hand()
        y.add_cards('AhAdAs2d', base_deck)
        self.assertTrue(len(y) == 4)

        #case 8: make sure we can't pull a card twice from a deck
        z = Hand()
        z.add_cards('AhAdAs2d5d', base_deck)
        self.assertTrue(len(z) == 1)
Exemple #2
0
    def test_deck(self):
        x = Deck()
        x.shuffle()

        #case 1:  make sure a shuffled deck has all the cards
        self.assertTrue(len(x) == 52)
        self.assertTrue(len(x.deck_state()) == 52)

        #case 2:  pull a single card and make sure the deck shrinks
        c = x.deal_one()
        self.assertTrue(len(x) == 51)
        self.assertTrue(len(x.deck_state()) == 51)

        #case 3:  reshuffle and make sure the deck is whole
        x.reset()
        self.assertTrue(len(x) == 52)
        self.assertTrue(len(x.deck_state()) == 52)

        #case 4:  reshuffle, take a specific card, and insure the deck shrinks
        x.reset()
        c = Card('Ah')
        x.take_card(c)
        self.assertTrue(len(x) == 51)

        #case 5:  make sure we can't take the same card twice
        self.assertTrue(x.take_card(c) == -1)

        #case 6:  get a five card hand
        x.reset()
        l = x.deal_hand(5)
        self.assertTrue(len(l) == 5)
        self.assertTrue(len(x) == 52-5)

        #case 7:  shuffle, make sure the length is unchanged
        x.shuffle()
        self.assertTrue(len(x) == 52-5)