def test_deck_draw(self):
        deck = CardCollection(self.deck)
        card_top = deck.top_card()
        card_bottom = deck.bottom_card()

        self.assertEqual(card_top, deck.draw_from_top())
        self.assertEqual(card_bottom, deck.draw_from_bottom())
        self.assertEqual(len(deck), 50)
示例#2
0
 def setUp(self):
     self.collection = [
         Card(RANKS['Ace'], SUITS['Diamonds']),
         Card(RANKS['Queen'], SUITS['Spades']),
         Card(RANKS['Two'], SUITS['Hearts']),
         Card(RANKS['Seven'], SUITS['Spades']),
         Card(RANKS['Ace'], SUITS['Diamonds']),
     ]
     self.deck = CardCollection(self.collection)
    def test_deck_add(self):
        deck = CardCollection()
        card1, card2 = random_cards(2)

        deck.add(card1)
        self.assertEqual(deck[0], card1)

        deck.add(card2)
        self.assertEqual(deck[1], card2)

        self.assertEqual(len(deck), 2)
示例#4
0
 def setUp(self):
     self.collection = [Card(RANKS['Ace'], SUITS['Diamonds']),
                        Card(RANKS['Queen'], SUITS['Spades']),
                        Card(RANKS['Two'], SUITS['Hearts']),
                        Card(RANKS['Seven'], SUITS['Spades']),
                        Card(RANKS['Ace'], SUITS['Diamonds']), ]
     self.deck = CardCollection(self.collection)
示例#5
0
    def test_deck_add(self):
        deck = CardCollection()
        card1, card2 = random_cards(2)

        deck.add(card1)
        self.assertEqual(deck[0], card1)

        deck.add(card2)
        self.assertEqual(deck[1], card2)

        self.assertEqual(len(deck), 2)
示例#6
0
class CardCollectionTest(unittest.TestCase):
    def setUp(self):
        self.collection = [
            Card(RANKS['Ace'], SUITS['Diamonds']),
            Card(RANKS['Queen'], SUITS['Spades']),
            Card(RANKS['Two'], SUITS['Hearts']),
            Card(RANKS['Seven'], SUITS['Spades']),
            Card(RANKS['Ace'], SUITS['Diamonds']),
        ]
        self.deck = CardCollection(self.collection)

    def test_top_card_returns_the_top_card(self):
        self.assertEqual(self.collection[-1], self.deck.top_card())

    def test_bottom_card_returns_the_bottom_card(self):
        self.assertEqual(self.collection[0], self.deck.bottom_card())

    def test_add_card_appends_card_to_deck(self):
        added_card = Card(RANKS['King'], SUITS['Diamonds'])
        self.deck.add(added_card)
        self.assertEqual(self.deck.top_card(), added_card)

    def test_draw_from_top_removes_top_card_and_returns_it(self):
        self.assertEqual(self.deck.draw_from_top(), self.collection[-1])
        self.assertEqual(self.collection[-2], self.deck.top_card())

    def test_draw_from_bottom_removes_bottom_card_and_returns_it(self):
        self.assertEqual(self.deck.draw_from_bottom(), self.collection[0])
        self.assertEqual(self.collection[1], self.deck.bottom_card())

    def test_index_returns_index_of_card(self):
        self.assertEqual(self.deck.index(self.collection[3]), 3)

    def test_index_return_first_occurences_of_card(self):
        self.assertEqual(self.deck.index(self.collection[4]), 0)

    def test_index_throws_value_error_if_item_is_missing(self):
        missing_card = Card(RANKS['Five'], SUITS['Spades'])
        self.assertRaises(ValueError, self.deck.index, missing_card)

    def test_is_iterable(self):
        self.assertIsInstance(self.deck, collections.Iterable)

    def test_is_indexable(self):
        self.assertTrue('__getitem__' in dir(self.deck))
示例#7
0
class CardCollectionTest(unittest.TestCase):
    def setUp(self):
        self.collection = [Card(RANKS['Ace'], SUITS['Diamonds']),
                           Card(RANKS['Queen'], SUITS['Spades']),
                           Card(RANKS['Two'], SUITS['Hearts']),
                           Card(RANKS['Seven'], SUITS['Spades']),
                           Card(RANKS['Ace'], SUITS['Diamonds']), ]
        self.deck = CardCollection(self.collection)

    def test_top_card_returns_the_top_card(self):
        self.assertEqual(self.collection[-1], self.deck.top_card())

    def test_bottom_card_returns_the_bottom_card(self):
        self.assertEqual(self.collection[0], self.deck.bottom_card())

    def test_add_card_appends_card_to_deck(self):
        added_card = Card(RANKS['King'], SUITS['Diamonds'])
        self.deck.add(added_card)
        self.assertEqual(self.deck.top_card(), added_card)

    def test_draw_from_top_removes_top_card_and_returns_it(self):
        self.assertEqual(self.deck.draw_from_top(), self.collection[-1])
        self.assertEqual(self.collection[-2], self.deck.top_card())

    def test_draw_from_bottom_removes_bottom_card_and_returns_it(self):
        self.assertEqual(self.deck.draw_from_bottom(), self.collection[0])
        self.assertEqual(self.collection[1], self.deck.bottom_card())

    def test_index_returns_index_of_card(self):
        self.assertEqual(self.deck.index(self.collection[3]), 3)

    def test_index_return_first_occurences_of_card(self):
        self.assertEqual(self.deck.index(self.collection[4]), 0)

    def test_index_throws_value_error_if_item_is_missing(self):
        missing_card = Card(RANKS['Five'], SUITS['Spades'])
        self.assertRaises(ValueError, self.deck.index, missing_card)

    def test_is_iterable(self):
        self.assertIsInstance(self.deck, collections.Iterable)

    def test_is_indexable(self):
        self.assertTrue('__getitem__' in dir(self.deck))
    def test_deck_draw(self):
        deck = CardCollection(self.deck)
        card = deck.top_card()

        self.assertEqual(card, deck.draw_from_top())
        self.assertEqual(len(deck), 51)
示例#9
0
 def test_deck_iteration(self):
     deck = CardCollection(self.deck)
     for card in deck:
         self.assertIsInstance(card, Card)
示例#10
0
    def test_deck_draw(self):
        deck = CardCollection(self.deck)
        card = deck.top_card()

        self.assertEqual(card, deck.draw_from_top())
        self.assertEqual(len(deck), 51)
示例#11
0
 def test_standard_deck(self):
     deck = CardCollection(self.deck)
     self.assertEqual(len(deck), 52)