def test_shoe_draw_should_return_first_card_and_remove_it_from_deck(self):
   shoe = blackjack.Shoe()
   shoe.cards = [blackjack.Card('club', 'an ace', 11), blackjack.Card('club', 'jack', 10)]
   first_card = shoe.draw()
   expect(first_card.figure == 'an ace' and first_card.color == 'club').to.be(True)
   expect(len(shoe.cards)).equal(1)
   expect(shoe.cards[0].figure == 'jack' and shoe.cards[0].color == 'club').to.be(True)
Exemple #2
0
    def test_check_dealer_for_blackjack(self):
        """
        Test that check_dealer_for_blackjack() function accurately
        recognizes when the dealer has been dealt a blackjack.
        """

        # create dealer & hand
        dealer = bj.Dealer()
        hand = bj.Hand()
        dealer.hands.append(hand)

        # 10, ace check
        card1 = bj.Card('Hearts', '*', 10)
        card2 = bj.Card('Hearts', '*', 1)
        hand.cards.append(card1)
        hand.cards.append(card2)
        self.assertTrue(bj.check_dealer_for_blackjack([dealer]))

        # ace, 10 check
        hand.first_iter = True
        hand.blackjack = False
        dealer.hands[0].cards[0].value = 1
        dealer.hands[0].cards[1].value = 10
        self.assertTrue(bj.check_dealer_for_blackjack([dealer]))

        # ace, 5 check
        hand.first_iter = True
        hand.blackjack = False
        dealer.hands[0].cards[1].value = 5
        self.assertFalse(bj.check_dealer_for_blackjack([dealer]))
 def test_hand(self):
     hand = blackjack.BlackJackHand()
     self.assertEqual(hand.total, 0)
     hand.add(blackjack.Card(1, 'spades'))
     self.assertEqual(hand.total, 11)
     hand.add(blackjack.Card(11, 'spades'))
     self.assertEqual(hand.total, 21)
     hand.add(blackjack.Card(13, 'spades'))
     self.assertEqual(hand.total, 21)
 def test_hand_should_contains_no_card_after_clear(self):
   hand = blackjack.Hand()
   card = blackjack.Card('club', 'an ace', 11)
   hand.add(card)
   card = blackjack.Card('spades', 'jack', 10)
   hand.add(card)
   expect(len(hand.cards)).equal(2)
   hand.clear()
   expect(len(hand.cards)).equal(0)
 def test_hand_should_have_added_card(self):
   hand = blackjack.Hand()
   expect(len(hand.cards)).equal(0)
   card = blackjack.Card('club', 'an ace', 11)
   hand.add(card)
   expect(len(hand.cards)).equal(1)
   expect(hand.cards[-1].figure=='an ace' and hand.cards[-1].color=='club').to.be(True)
   card = blackjack.Card('spades', 'jack', 10)
   hand.add(card)
   expect(len(hand.cards)).equal(2)
   expect(hand.cards[-1].figure=='jack' and hand.cards[-1].color=='spades').to.be(True)
 def test_hand_should_return_correct_number_of_ace(self):
   hand = blackjack.Hand()
   expect(hand.number_of_ace()).equal(0)
   card = blackjack.Card('club', 'an ace', 11)
   hand.add(card)
   expect(hand.number_of_ace()).equal(1)
   card = blackjack.Card('spades', 'jack', 10)
   hand.add(card)
   expect(hand.number_of_ace()).equal(1)
   card = blackjack.Card('spades', 'an ace', 11)
   hand.add(card)
   expect(hand.number_of_ace()).equal(2)
 def test_hand_should_evalute_correctly(self):
   hand = blackjack.Hand()
   card = blackjack.Card('club', 'an ace', 1)
   hand.add(card)
   expect(hand.evaluate()).equal(11)
   card = blackjack.Card('club', '4', 4)
   hand.add(card)
   expect(hand.evaluate()).equal(15)
   card = blackjack.Card('club', 'jack', 10)
   hand.add(card)
   expect(hand.evaluate()).equal(15)
   card = blackjack.Card('spades', 'an as', 1)
   hand.add(card)
   expect(hand.evaluate()).equal(16)
Exemple #8
0
 def test_num_aces(self):
     # Add 10 aces
     for x in range(10):
         new_card = blackjack.Card("Spades", 1)
         self.player.hit(new_card)
         num_aces, ignore = blackjack.update_value_and_aces(self.player)
         self.assertEqual(num_aces, x + 1)
 def setUp(self):
     '''
     Create a card object at the beginning of each test
     '''
     self.rank = "Ace"
     self.suit = "Spades"
     self.card = blackjack.Card(self.rank, self.suit)
 def test_create_valid_cards(self):
     '''
     creates all valid cards and test the creation
     '''
     for value in range(14):
         for suit in ['clubs', 'hearts', 'spades', 'diamonds']:
             card = blackjack.Card(value, suit)
             self.assertIsInstance(card, blackjack.Card)
Exemple #11
0
    def test_ace(self):
        # Creating card objects for ace check
        ace = blackjack.Card("♣", 'A')
        king = blackjack.Card("♣", 'K')
        queen = blackjack.Card("♣", 'Q')

        # Creating the player's hand
        playerHand = [ace, king, queen]
        hand = blackjack.Hand([])
        hand.setNumCards(3)

        # Hand value should be 21, this shows ace's
        # will switch from 11 to 1
        val = hand.handValue(playerHand)
        actual = val
        expected = 21

        # Check if hand is equal to 21
        self.assertEqual(expected, actual, "Failed ace test")
Exemple #12
0
    def test_two_ace(self):
        # Creating card objects for hand with 2 aces
        aceOne = blackjack.Card("♣", 'A')
        aceTwo = blackjack.Card("♣", 'A')
        queen = blackjack.Card("♣", 'Q')
        nine = blackjack.Card("♣", '9')

        # Creating the player's hand
        playerHand = [aceOne, aceTwo, queen, nine]
        hand = blackjack.Hand([])
        hand.setNumCards(4)

        # Hand value should be 21, this shows ace's
        # will switch from 11 to 1 even while 2 are in hand
        val = hand.handValue(playerHand)
        actual = val
        expected = 21

        # Check if hand is equal to 21
        self.assertEqual(expected, actual, "Failed two ace test")
Exemple #13
0
 def test_total(self):
     count = 0
     # Add 1 - 10
     for x in range(1, 11):
         new_card = blackjack.Card("Spades", x)
         self.player.hit(new_card)
         ignore, total = blackjack.update_value_and_aces(self.player)
         # Ace is worth 11 out of context
         if x == 1:
             test = 11
         else:
             test = x
         self.assertEqual(total, count + test)
         count += test
Exemple #14
0
 def setUp(self):
     self.hand = blackjack.Hand(blackjack.Deck())
     self.dealer_hand = blackjack.DealerHand(blackjack.Deck())
     self.example_hard_cards = [blackjack.Card(
         13, 'Diamonds'), blackjack.Card(4, 'Clubs')]
     self.example_soft_cards = [blackjack.Card(1, 'Hearts'),
                                blackjack.Card(6, 'Diamonds')]
     self.example_blackjack_cards = [blackjack.Card(1, 'Spades'),
                                     blackjack.Card(13, 'Hearts')]
Exemple #15
0
 def setUp(self):
     self.deck = blackjack.Deck()
     self.hand = blackjack.Hand(self.deck)
     self.card = blackjack.Card(12, 'Any suit')
Exemple #16
0
 def setUp(self):
     self.card = (blackjack.Card(12, 'Any suit'))
 def test_as_card_should_is_ace(self):
   ace_card = blackjack.Card('club', 'an ace', 11)
   expect(ace_card.is_ace).to.be(True)
Exemple #18
0
 def test_card(self):
     """Check the Card class"""
     card = blackjack.Card("a", "b")
     self.assertEqual(card.suit, 'a')
     self.assertEqual(card.rank, 'b')
     self.assertEqual(str(card), 'b of a')
 def test_string_value(self):
     self.assertEqual('A♣', str(blackjack.Card(1, 'clubs')))