def test_user_pushes_with_blackjack(self): """ Test that the user pushes with blackjack when the dealer also has a blackjack """ test_shoe = self.test_shoe player_list = self.test_player_list dealer = self.dealer player = player_list[0] test_shoe.cards.insert(0, card(10, "H")) test_shoe.cards.insert(1, card(10, "C")) test_shoe.cards.insert(2, card(1, "H")) initial_deal(test_shoe, player_list, dealer) self.assertEqual(player.get_score(), 21) dealer_play(test_shoe, dealer) self.assertTrue(check_blackjack(dealer.get_score(), dealer.get_hand())) self.assertTrue(check_blackjack(player.get_score(), player.get_hand())) results = check_results(player_list, dealer) pushers = results[2] self.assertIn(player, pushers)
def test_user_stands_with_blackjack(self): """ Test that a user automatically stands when they have blackjack """ test_shoe = self.test_shoe player_list = self.test_player_list dealer = self.dealer player = player_list[0] test_shoe.cards.insert(0, card(10, "H")) test_shoe.cards.insert(2, card(1, "H")) initial_deal(test_shoe, player_list, dealer) self.assertEqual(player.get_score(), 21) self.assertTrue(check_blackjack(player.get_score(), player.get_hand()))
def test_user_wins_with_blackjack(self): """ Test that the user wins when they get blackjack and they get the custom message """ test_shoe = self.test_shoe player_list = self.test_player_list dealer = self.dealer player = player_list[0] test_shoe.cards.insert(0, card(10, "H")) test_shoe.cards.insert(2, card(1, "H")) initial_deal(test_shoe, player_list, dealer) self.assertEqual(player.get_score(), 21) self.assertTrue(check_blackjack(player.get_score(), player.get_hand())) dealer_play(test_shoe, dealer) results = check_results(player_list, dealer) blackjack_winners = results[3] self.assertIn(player, blackjack_winners)
def test_user_stands_on_21(self): """ Test that a user automatically stands when they hit 21 """ test_shoe = self.test_shoe player_list = self.test_player_list dealer = self.dealer player = player_list[0] test_shoe.cards.insert(0, card(10, "H")) test_shoe.cards.insert(2, card(3, "H")) test_shoe.cards.insert(4, card(8, "D")) initial_deal(test_shoe, player_list, dealer) with mock.patch('builtins.input', return_value="hit"): user_play(test_shoe, player, dealer) self.assertEqual(player.get_score(), 21) self.assertFalse(check_blackjack(player.get_score(), player.get_hand()))
def test_user_pushes(self): """ Test that when a user's score and the dealer's score are the same they push """ test_shoe = self.test_shoe player_list = self.test_player_list dealer = self.dealer player = player_list[0] test_shoe.cards.insert(0, card(8, "H")) test_shoe.cards.insert(1, card(10, "C")) test_shoe.cards.insert(2, card(9, "C")) test_shoe.cards.insert(3, card(6, "D")) initial_deal(test_shoe, player_list, dealer) dealer_play(test_shoe, dealer) self.assertEqual(player.get_score(), dealer.get_score()) self.assertFalse(check_blackjack(player.get_score(), player.get_hand())) results = check_results(player_list, dealer) pushers = results[2] self.assertIn(player, pushers)
def test_user_loses(self): """ Test that a user loses when the dealer's score exceeds theirs and the dealer doesn't bust """ test_shoe = self.test_shoe player_list = self.test_player_list dealer = self.dealer player = player_list[0] test_shoe.cards.insert(0, card(8, "H")) test_shoe.cards.insert(1, card(10, "C")) test_shoe.cards.insert(2, card(8, "C")) test_shoe.cards.insert(3, card(6, "D")) initial_deal(test_shoe, player_list, dealer) dealer_play(test_shoe, dealer) self.assertLess(player.get_score(), dealer.get_score()) self.assertFalse(check_blackjack(player.get_score(), player.get_hand())) results = check_results(player_list, dealer) losers = results[1] self.assertIn(player, losers)
def test_user_wins_when_dealer_busts(self): """ Test that a user wins when the dealer exceeds 21 as long as they have not also bust themselves """ test_shoe = self.test_shoe player_list = self.test_player_list dealer = self.dealer player = player_list[0] test_shoe.cards.insert(0, card(8, "H")) test_shoe.cards.insert(1, card(10, "C")) test_shoe.cards.insert(2, card(8, "C")) test_shoe.cards.insert(3, card(6, "D")) test_shoe.cards.insert(4, card(10, "D")) initial_deal(test_shoe, player_list, dealer) dealer_play(test_shoe, dealer) self.assertTrue(dealer.check_bust()) self.assertFalse(check_blackjack(player.get_score(), player.get_hand())) results = check_results(player_list, dealer) winners = results[0] self.assertIn(player, winners)