예제 #1
0
def test_Hand_add_single_card(card):
    # Setup
    hand = blackjack.Hand()

    # Exercise
    hand.add_card(card)

    # Verify
    assert hand.cards == [card]
예제 #2
0
def test_BlackJack_check_for_blackjack():
    # Setup
    hand_non_blackjack = blackjack.Hand()
    hand_non_blackjack.add_card(blackjack.Card(10, "diamonds"))
    hand_non_blackjack.add_card(blackjack.Card(5, "hearts"))

    hand_blackjack = blackjack.Hand()
    hand_blackjack.add_card(blackjack.Card(10, "diamonds"))
    hand_blackjack.add_card(blackjack.Card("Ace", "hearts"))

    game = blackjack.BlackJack()

    # Exercise
    result_non_blackjack = game.check_for_blackjack(hand_non_blackjack)
    result_blackjack = game.check_for_blackjack(hand_blackjack)

    # Verify
    assert not result_non_blackjack
    assert result_blackjack
예제 #3
0
def test_Hand_add_multi_cards(cards):
    # Setup
    hand = blackjack.Hand()

    # Exercise
    for card in cards:
        hand.add_card(card)

    # Verify
    assert hand.cards == list(cards)
예제 #4
0
def test_Hand_instantiation(dealer):
    # Setup - none necessary

    # Exercise
    hand = blackjack.Hand(dealer=dealer)

    # Verify
    if dealer:
        assert hand.dealer
    else:
        assert not hand.dealer
    assert hand.cards == []
    assert hand.value == 0
예제 #5
0
def test_BlackJack_check_player_bust(cards, expected_bust):
    # Setup
    game = blackjack.BlackJack()

    game.player_hand = blackjack.Hand()

    for card in cards:
        game.player_hand.add_card(card)

    # Exercise
    result = game.check_player_bust()

    # Verify
    assert result is expected_bust
예제 #6
0
def test_Hand_calculate_value(card_values, expected_hand_value):
    # Setup
    card_1 = blackjack.Card(card_values[0], "diamonds")
    card_2 = blackjack.Card(card_values[1], "diamonds")

    hand = blackjack.Hand()
    hand.add_card(card_1)
    hand.add_card(card_2)

    # Exercise
    hand.calculate_value()

    # Verify
    assert hand.value == expected_hand_value
예제 #7
0
def test_Hand_get_value(card_values, expected_hand_value):
    # Setup
    card_1 = blackjack.Card(card_values[0], "diamonds")
    card_2 = blackjack.Card(card_values[1], "diamonds")

    hand = blackjack.Hand()
    hand.add_card(card_1)
    hand.add_card(card_2)

    # Exercise
    result = hand.get_value()

    # Verify
    assert result == expected_hand_value
    assert result == hand.value
예제 #8
0
def test_Hand_display(dealer, capsys):
    # Setup
    card_1 = blackjack.Card(5, "diamonds")
    card_2 = blackjack.Card("King", "diamonds")

    hand = blackjack.Hand(dealer=dealer)
    hand.add_card(card_1)
    hand.add_card(card_2)

    expected_out = "Card 1: 5 of diamonds\nCard 2: King of diamonds\nHand Total: 15\n"

    if dealer:
        expected_out = (
            f"Card 1: {Fore.BLUE}hidden{Style.RESET_ALL}\nCard 2: King of diamonds\n"
        )

    # Exercise
    hand.display()

    # Verify
    captured = capsys.readouterr()
    assert captured.out == expected_out