added Hand() tests

This commit is contained in:
2025-10-29 18:48:52 +01:00
parent 7979767b3d
commit 4ae994b554

View File

@@ -1,7 +1,9 @@
import pytest
from pyjack.card import Card
from pyjack.hand import Hand
@pytest.fixture
def default_hand():
my_hand = Hand()
@@ -9,5 +11,35 @@ def default_hand():
def test_adding_card_to_hand(default_hand):
default_hand.add_card("diamonds","2")
default_hand.add_card("diamonds","K")
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