2025-10-29 17:37:55 +01:00
|
|
|
import pytest
|
|
|
|
|
|
2025-10-29 18:48:52 +01:00
|
|
|
from pyjack.card import Card
|
2025-10-29 17:37:55 +01:00
|
|
|
from pyjack.hand import Hand
|
|
|
|
|
|
2025-10-29 18:48:52 +01:00
|
|
|
|
2025-10-29 17:37:55 +01:00
|
|
|
@pytest.fixture
|
|
|
|
|
def default_hand():
|
|
|
|
|
my_hand = Hand()
|
|
|
|
|
return my_hand
|
|
|
|
|
|
2025-10-29 17:49:42 +01:00
|
|
|
|
2025-10-29 17:37:55 +01:00
|
|
|
def test_adding_card_to_hand(default_hand):
|
2025-10-29 18:48:52 +01:00
|
|
|
default_hand.add_card(Card("diamonds", "2"))
|
|
|
|
|
default_hand.add_card(Card("spades", "A"))
|
|
|
|
|
|
|
|
|
|
assert default_hand.value == 13
|
|
|
|
|
assert len(default_hand.cards) == 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_adjusting_for_ace(default_hand):
|
|
|
|
|
"""Tests if the value of an ace is adjusted if the hand holds 1 ace
|
|
|
|
|
and two cards, making the value of the hand > 21"""
|
|
|
|
|
|
|
|
|
|
# Creating a hand with a value pre adjustment of 31
|
|
|
|
|
cards = [Card("spades", "10"), Card("diamonds", "K"), Card("heart", "A")]
|
|
|
|
|
for card in cards:
|
|
|
|
|
default_hand.add_card(card)
|
|
|
|
|
|
|
|
|
|
default_hand.adjust_for_aces()
|
|
|
|
|
|
|
|
|
|
assert default_hand.value == 21
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def testing_adjusting_for_multiple_aces(default_hand):
|
|
|
|
|
""" "Testing if multiple aces a treated correctly, resulting in the
|
|
|
|
|
hands value to be 12."""
|
|
|
|
|
# Creating a hand with a value pre adjustment of 32
|
|
|
|
|
cards = [Card("spades", "10"), Card("diamonds", "A"), Card("heart", "A")]
|
|
|
|
|
for card in cards:
|
|
|
|
|
default_hand.add_card(card)
|
|
|
|
|
|
|
|
|
|
default_hand.adjust_for_aces()
|
|
|
|
|
|
|
|
|
|
assert default_hand.value == 12
|