Esempio n. 1
0
 def test_game_decision_when_points_over_17(self):
     d = Dealer("test_dealer")
     # test dealer - give hand with high points
     card_list = [Card("S", "10"), Card("H", "J")]
     d.add_card_to_hand(card_list)
     # check that the function will return false to not take another card
     self.assertFalse(d.make_game_decision())
Esempio n. 2
0
    def test_get_color_func(self):
        # arrange
        c = Card(CardUtils.get_possible_suits()[0], CardUtils.get_possible_colors()[0], CardUtils.get_possible_numbers()[0])

        # act
        col = c.get_color()

        # assert
        self.assertTrue(col in CardUtils.get_possible_colors())
 def test_get_points_with_multiple_aces(self):
     card_list = [Card("S", "A"), Card("H", "A")]
     self.p.add_card_to_hand(card_list)
     score = self.p.get_points_of_hand()
     self.p.add_card_to_hand([Card("C", "A")])
     score_two = self.p.get_points_of_hand()
     self.p.add_card_to_hand([Card("D", "9")])
     #check all the scores are adjusted as expected on adding aces to hand
     self.assertTrue(score == 12 and score_two == 13
                     and self.p.get_points_of_hand() == 12)
 def test_show_hand_gives_expected_string(self):
     card_list = [Card("S", "10"), Card("H", "J")]
     self.p.add_card_to_hand(card_list)
     with io.StringIO() as buffer:
         # redirect the stdout to the buffer - whatever goes to stdout will go to buffer
         with contextlib.redirect_stdout(buffer):
             # what is printed in this with will be redirected to the buffer; act
             self.p.show_hand()
             printed_text = buffer.getvalue()
         # assert - getvalue from buffer - check it contains expected phrase twice
         self.assertTrue(printed_text.count("The card is:") == 2)
Esempio n. 5
0
 def test_show_card(self):
     #arrange - make the card
     c = Card(CardUtils.get_possible_suits()[0],
              CardUtils.get_possible_numbers()[0])
     with io.StringIO() as buffer:
         #redirect the stdout to the buffer - whatever goes to stdout will go to buffer
         with contextlib.redirect_stdout(buffer):
             #what is printed in this with will be redirected to the buffer; act
             c.show()
         #assert - getvalue from buffer - check it is the same as the string
         self.assertTrue(buffer.getvalue().strip() == c.to_string())
Esempio n. 6
0
 def test_dealer_showing_cards_in_player_turn_only_shows_one(self):
     d = Dealer("test_dealer")
     card_list = [Card("S", "10"), Card("H", "J")]
     d.add_card_to_hand(card_list)
     with io.StringIO() as buffer:
         # redirect the stdout to the buffer - whatever goes to stdout will go to buffer
         with contextlib.redirect_stdout(buffer):
             # what is printed in this with will be redirected to the buffer; act
             d.show_hand_during_player_turn()
             printed_text = buffer.getvalue()
         # assert - getvalue from buffer - check it only tells once the card is
         self.assertTrue(printed_text.count("The card is:") == 1)
Esempio n. 7
0
    def test_show_func_list_input(self):
        # arrange
        c = Card(
            random.choice(CardUtils.get_possible_suits()),
            random.choice(CardUtils.get_possible_colors()),
            random.choice(CardUtils.get_possible_numbers())
        )

        with io.StringIO() as buf:
            # act
            with contextlib.redirect_stdout(buf):
                c.show()
            # assert
            self.assertTrue(buf.getvalue().strip() == c.to_string())
Esempio n. 8
0
 def test_get_card_value(self):
     list_of_values = []
     for n in CardUtils.get_possible_numbers():
         # for each possibly number in one suit, add the value of card to list
         list_of_values.append(Card("D", n).get_card_value())
     # checks the list of values is as expected for suit
     self.assertTrue(
         list_of_values == [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11])
Esempio n. 9
0
 def test_card_for_number(self):
     flag = False
     try:
         Card(CardUtils.get_possible_suits()[0], CardUtils.get_possible_colors()[0], "asd")
     except RuntimeError:
         flag = True
     if flag:
         self.assertTrue(True)
     else:
         self.assertTrue(False)
Esempio n. 10
0
 def test_card_for_number(self):
     flag = False
     try:
         Card(
             CardUtils.get_possible_suits()[0], "uiu"
         )  #here we want to have num wrong (to make sure get exception) rest right
     except RuntimeError:
         flag = True  #if there is something wrong i the card num the flag will become true
     if flag:
         self.assertTrue(
             True)  #is always true - this is true if there is exception
     else:
         self.assertTrue(False)
Esempio n. 11
0
 def test_card_creation(self):
     flag = True
     try:
         Card(
             CardUtils.get_possible_suits()[0],
             CardUtils.get_possible_numbers()[0]
         )  #here we want to have suit wrong (to make sure get exception) rest right
     except RuntimeError:
         flag = False  #if we do get error test has failed (not passed as all should be ok)
     if flag:
         self.assertTrue(True)
     else:
         self.assertTrue(False)
Esempio n. 12
0
 def init_deck(self):
     for i_col in CardUtils.get_possible_colors():
         for i_suit in CardUtils.get_possible_suits():
             for i_num in CardUtils.get_possible_numbers():
                 self.deck.append(Card(i_suit, i_col, i_num))
Esempio n. 13
0
 def test_game_decision_when_points_under_17(self):
     d = Dealer("test_dealer")
     card_list = [Card("S", "2"), Card("H", "7")]
     d.add_card_to_hand(card_list)
     self.assertTrue(d.make_game_decision())
Esempio n. 14
0
 def test_get_suit_function(self):
     c = Card(CardUtils.get_possible_suits()[0],
              CardUtils.get_possible_numbers()[0])
     suit = c.get_suit()
     self.assertTrue(suit in CardUtils.get_possible_suits())
Esempio n. 15
0
 def test_get_points_of_hand_gives_expected_value(self):
     card_list = [Card("S", "10"), Card("H", "J")]
     self.p.add_card_to_hand(card_list)
     score = self.p.get_points_of_hand()
     self.p.add_card_to_hand([Card("H", "A")])
     self.assertTrue(score == 20 and self.p.get_points_of_hand() == 21)
Esempio n. 16
0
 def test_addition_of_cards_to_hand_gives_expected_number_in_hand(self):
     card_list = [Card("S", "10"), Card("H", "J")]
     self.p.add_card_to_hand(card_list)
     self.assertTrue((len(self.p.get_hand()) == 2))
Esempio n. 17
0
 def init_deck(self):
     #go through the possible suits (4) and for each get the possible numbers then mark as red or blue for colour depending on the suit - colour not actually needed
     for i_suit in CardUtils.get_possible_suits():
         for i_num in CardUtils.get_possible_numbers():
             #each of the cards added to list of cards in deck
             self.deck.append(Card(i_suit, i_num))
Esempio n. 18
0
 def test_get_number_function(self):
     c = Card(CardUtils.get_possible_suits()[0],
              CardUtils.get_possible_numbers()[0])
     number = c.get_number()
     self.assertTrue(number in CardUtils.get_possible_numbers())