def test_assess_hand_with_two_aces(): """ Test that assess_hand algorithm will adjust the value(s) of Aces(s) to ensure a maximum, non-bust value """ game = BlackJack() game.dealer_hand['A'].append(11) game.dealer_hand['A'].append(11) game.dealer_hand['9'].append(9) game.aces_drawn = 2 # Before calling assess_hand it should bust assert game.is_bust(game.dealer_hand) # call assess_hand to adjust value game.assess_hand(game.dealer_hand) # one of the 11s should be adjusted to 1 to prevent busting assert game.dealer_hand['A'][0] == 1 assert not game.is_bust(game.dealer_hand) assert game.total_value(game.dealer_hand) == 21
def test_bust(): """Manually deal hands and test dealer busts""" game = BlackJack() # Dealer game.dealer_hand['6'].append(6) game.dealer_hand['J'].append(10) # Player game.player_hand['10'].append(10) game.player_hand['J'].append(10) game.assess_both_hands(game.player_hand, game.dealer_hand) # Assume Player stood here # Dealer's turn # Dealer hits because total is still < 17 game.dealer_hand['6'].append(6) # to ensure bust game.assess_hand(game.dealer_hand) # Dealer busts when > 21 assuming Player hasn't busted or blackjacked assert game.is_bust(game.dealer_hand) assert not game.is_bust(game.player_hand) assert not game.is_blackjack(game.player_hand)
def test_early_not_bust(): """Initial two cards can never bust""" game = BlackJack() # Deal hands randomly using deal_card for _ in range(2): game.draw_card(game.player_hand) game.draw_card(game.dealer_hand) game.assess_both_hands(game.player_hand, game.dealer_hand) # Should never bust since in the worst case A A will adjust to 1 11 assert not game.is_bust(game.player_hand)
def test_player_higher_than_dealer(): """Manually deal hands and test that player is higher than dealer""" game = BlackJack() game.player_hand['A'].append(11) game.player_hand['A'].append(11) game.player_hand['7'].append(7) game.dealer_hand['5'].append(5) game.dealer_hand['5'].append(5) game.dealer_hand['7'].append(7) game.aces_drawn = 2 game.assess_both_hands(game.player_hand, game.dealer_hand) assert not game.is_bust(game.player_hand) assert game.total_value(game.player_hand) > game.total_value( game.dealer_hand)