class TestHand(unittest.TestCase): @classmethod def setUpClass(cls): cls.card_library = CardLibrary() def setUp(self): self.cards_in_hand = [ self.card_library.get_card(name="Island"), self.card_library.get_card(name="Island"), self.card_library.get_card(name="Swamp"), self.card_library.get_card("Cryptic Command") ] self.example_hand = Hand(cards=self.cards_in_hand) self.initial_hand_size = self.example_hand.size def test_size(self): """ Checks that the Hand.size property returns the number of cards within a Hand. """ self.assertEqual(self.example_hand.size, len(self.cards_in_hand)) def test_draw(self): pass def test_add_card(self): """ Checks that the add_card() method adds a Card to a Hand. """ another_forest = self.card_library.get_card(name="Forest") self.assertEqual(self.example_hand.size, self.initial_hand_size) self.example_hand.add_card(another_forest) self.assertEqual(self.example_hand.size, self.initial_hand_size + 1) self.assertIn(another_forest, self.example_hand) def test_play_land(self): """ Checks that the play_land() method returns a land Card from a deck if one is available. """ output_card = self.example_hand.play_land() self.assertIsInstance(output_card, Card) self.assertTrue(output_card.is_land) self.assertEqual(self.example_hand.size, self.initial_hand_size - 1) def test_has_playable_land(self): """ Checks that the has_playable_land property correctly reports whether or not a Hand contains a playable land. """ #Example hand starts off with three playable lands, so #after three land plays there should be no more playable lands self.assertTrue(self.example_hand.has_playable_land) self.example_hand.play_land() self.assertTrue(self.example_hand.has_playable_land) self.example_hand.play_land() self.assertTrue(self.example_hand.has_playable_land) self.example_hand.play_land() self.assertFalse(self.example_hand.has_playable_land) def test_land_priority_strategy(self): pass
def test_add_card_one_not_ace(self): """ Tests the state of adding 1 non-ace card to the hand """ h = Hand() card = Card('king', [10]) h.add_card(card) self.assertListEqual(list(h.get_possible_scores()), [10]) self.assertListEqual(list(h.get_cards()), [card]) expected_tree = BinaryTree(BinaryTreeNode(0, BinaryTreeNode(10))) self.assertTrue(h.hands.is_equivalent(expected_tree))
def test_blackjack(self): """ Tests whether a blackjack (21 valued hand) is correctly identified """ h = Hand() card1 = Card('ace', [1, 11]) card2 = Card('king', [10]) h.add_card(card1) self.assertFalse(h.has_blackjack()) h.add_card(card2) self.assertTrue(h.has_blackjack())
def test_add_card_multiple_no_ace(self): """ Tests the state of adding multiple non-ace cards to the hand """ h = Hand() card1 = Card('two', [2]) card2 = Card('king', [10]) h.add_card(card1) h.add_card(card2) self.assertListEqual(list(h.get_possible_scores()), [12]) self.assertListEqual(list(h.get_cards()), [card1, card2]) expected_tree = BinaryTree( BinaryTreeNode(0, BinaryTreeNode(2, BinaryTreeNode(12)))) self.assertTrue(h.hands.is_equivalent(expected_tree))
def test_get_priority_bust(self): """ Tests whether the correct priority is assigned to busted hands """ h = Hand() card1 = Card('ace', [1, 11]) card2 = Card('king', [10]) h.add_card(card1) self.assertEqual(h.get_priority(), 11) h.add_card(card2) self.assertEqual(h.get_priority(), 21) h.add_card(card2) self.assertEqual(h.get_priority(), 21) h.add_card(card2) self.assertEqual(h.get_priority(), -31)
def test_best_score_w_ace(self): """ Tests whether the correct best score is returned, including aces. """ h = Hand() card1 = Card('ace', [1, 11]) card2 = Card('king', [10]) h.add_card(card1) self.assertEqual(h.get_best_score(), 11) h.add_card(card2) self.assertEqual(h.get_best_score(), 21) h.add_card(card2) self.assertEqual(h.get_best_score(), 21) h.add_card(card2) self.assertEqual(h.get_best_score(), 31)
def test_is_bust_w_ace(self): """ Tests whether a bust (all possible values > 21) is correctly identified, including aces. """ h = Hand() card1 = Card('ace', [1, 11]) card2 = Card('king', [10]) h.add_card(card1) self.assertFalse(h.is_bust()) h.add_card(card2) self.assertFalse(h.is_bust()) h.add_card(card2) self.assertFalse(h.is_bust()) h.add_card(card2) self.assertTrue(h.is_bust())
def test_best_score_no_ace(self): """ Tests whether the correct best score is returned, excluding aces. """ h = Hand() card = Card('king', [10]) h.add_card(card) self.assertEqual(h.get_best_score(), 10) h.add_card(card) self.assertEqual(h.get_best_score(), 20) h.add_card(card) self.assertEqual(h.get_best_score(), 30)