class TestDeck(unittest.TestCase): @classmethod def setUpClass(cls): cls.card_library = CardLibrary() def setUp(self): self.example_card_1 = self.card_library.get_card(name="Plains") self.example_card_2 = self.card_library.get_card(name="Island") self.example_card_3 = self.card_library.get_card(name="Swamp") self.example_card_4 = self.card_library.get_card(name="Mountain") self.example_card_5 = self.card_library.get_card(name="Forest") self.example_deck = Deck([ self.example_card_1, self.example_card_2, self.example_card_3, self.example_card_4, self.example_card_5 ]) def test_shuffle(self): """ Checks whether or not the shuffle() method randomly reorders the cards in a Deck. """ self.example_deck.shuffle() drawn_card = self.example_deck.draw() self.assertIsNot(drawn_card, self.example_card_1) def test_draw(self): """ Checks whether or not the draw() method correctly removes and returns a Card from a Deck. """ initial_size = self.example_deck.size drawn_card = self.example_deck.draw() self.assertIsInstance(drawn_card, Card) self.assertEqual(self.example_deck.size, initial_size - 1) def test_add_card(self): """ Checks that the Deck.add_card() method adds a Card to a Deck. """ another_card = self.card_library.get_card(name="Wasteland") self.assertNotIn(another_card, self.example_deck) self.example_deck._add_card(another_card) self.assertIn(another_card, self.example_deck) def test_add_cards(self): """ Checks that the Deck.add_cards() method adds multiple Cards to a Deck. """ another_card = self.card_library.get_card(name="Wasteland") another_card_2 = self.card_library.get_card(name="Strip Mine") self.assertNotIn(another_card, self.example_deck) self.assertNotIn(another_card_2, self.example_deck) self.example_deck._add_cards([another_card, another_card_2]) self.assertIn(another_card, self.example_deck) self.assertIn(another_card_2, self.example_deck)
def test_draw_simple(self): """ This tests whether the state of the deck is correctly updated following a series of draws """ d = Deck() d.draw() self.assertEqual(sum(d.cards), 51) d.draw() d.draw() self.assertEqual(sum(d.cards), 49) for _, card in d.card_mapping.items(): # ensure cards remain generic self.assertIsNone(card.get_suit())
def test_draw_edge(self): """ This tests whether the deck can correctly be drawn from until exhaustion """ d = Deck() curr_num_cards = 52 while d.draw(): curr_num_cards -= 1 self.assertEqual(sum(d.cards), curr_num_cards)