예제 #1
0
 def test_restore(self):
     x = Deck()
     x.shuffle()
     
     y = x.deck_state()
     z = Deck()
     self.assertTrue(z.restore_deck(y) == True)
     self.assertTrue(z.deck_state() == x.deck_state())
     z.shuffle()
     self.assertFalse(z.deck_state() == x.deck_state())
예제 #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)