Exemplo n.º 1
0
 def test_correct_card_returned_given_a_suit_and_rank(self):
     '''
     This function is testing :
      1. The correct card object is created for a given rank and suit and
      2. the definition of __str__ inside the Card class.
     '''
     rank = "Two"
     suit = "Hearts"
     sample_card = Card(rank, suit)
     actual_result = sample_card.__str__()
     self.assertEqual(actual_result, "Two of Hearts")
Exemplo n.º 2
0
    def test_the_correct_card_is_added_when_add_card_is_called(self):
        '''
        Test the add_card method in Hand class
        '''
        expected_cards_in_hand = [Card("Ace", "Hearts"), Card("Ace", "Spades")]
        expected_value = 21
        expected_hand_length = 2

        self.test_hand.add_card(expected_cards_in_hand[0])
        self.test_hand.add_card(expected_cards_in_hand[1])

        self.assertEqual(expected_cards_in_hand, self.test_hand.cards)
        self.assertEqual(expected_value, self.test_hand.value)
        self.assertEqual(expected_hand_length, len(self.test_hand))
Exemplo n.º 3
0
 def setUp(self):
     '''
     This method sets up the common variables for all the \
     unit tests in this module
     '''
     self.game = Game()
     self.player_hand = Hand()
     self.dealer_hand = Hand()
     self.card_deck = Deck()
     self.dealer_hand.add_card(Card("Ace", "Hearts"))
     self.dealer_hand.add_card(Card("Ace", "Spades"))
     self.player_hand.add_card(Card("2", "Hearts"))
     self.player_hand.add_card(Card("3", "Hearts"))
     self.player_chips = Chips()
     self.dealer_chips = Chips()
Exemplo n.º 4
0
 def __init__(self):
     '''
     Initialises the deck object by creating 52 cards of a playing card deck
     '''
     self.cards = []
     for suit in self.suits:
         for rank in self.ranks:
             self.cards.append(Card(rank, suit))
Exemplo n.º 5
0
    def test_an_error_is_raised_when_a_card_other_than_ace_is_used_with_adjust_for_ace(
            self):
        '''
        Test the adjust_for_ace method in the Hand class when a card other than an ace is used.
        '''
        with self.assertRaises(Exception) as context:
            self.test_hand.adjust_for_ace(Card("2", "Hearts"))

        self.assertEqual("It is not an ace.", str(context.exception))
Exemplo n.º 6
0
    def test_the_correct_value_of_ace_is_used_when_total_hand_value_is_9(self):
        '''
        Test the adjust_for_ace method in the Hand class when the total value of hand is 9
        '''
        expected_value = 20
        self.test_hand.value = 9
        self.test_hand.adjust_for_ace(Card("Ace", "Hearts"))

        self.assertEqual(expected_value, self.test_hand.value)
Exemplo n.º 7
0
    def test_given_suits_and_ranks_build_the_card_deck(self):
        '''
        Tests that when a deck object is created a deck of 52 cards has been generated
        '''
        expected_result = []
        for suit in self.suits:
            for rank in self.ranks:
                expected_result.append(Card(rank, suit))
        self.test_deck.__init__()
        self.assertEqual(expected_result[0].__str__(), \
                        self.test_deck.cards[0].__str__())

        self.assertEqual(expected_result[34].__str__(), \
                        self.test_deck.cards[34].__str__())