fixed test in deck and added hand

test
This commit is contained in:
2025-10-29 17:37:55 +01:00
parent ed494ec8b2
commit 6e4e71c95b
2 changed files with 30 additions and 3 deletions

View File

@@ -13,10 +13,25 @@ def test_deck_init(default_deck):
assert len(default_deck.cards) == 52 assert len(default_deck.cards) == 52
def test_shuffle_deck(default_deck): def test_deck_shuffle_order_changes(default_deck):
"""Tests if the deck is randomized after method call""" """Tests if the order of the cards have been changed."""
assert default_deck != default_deck.shuffle() # saves a list of cards before shufflening
ordered_cards = list(default_deck.cards)
#shuffle cards
default_deck.shuffle()
assert default_deck.cards != ordered_cards
def test_deck_shuffle_content_is_preserved(default_deck):
# 1. Capture the unique cards of the original list (as a set)
original_card_set = set(str(card) for card in default_deck.cards)
# 2. Shuffle the deck
default_deck.shuffle()
# 3. Check if the number of cards is still 52
assert len(default_deck.cards) == 52
# 4. Check if the card contents are still identical (all 52 unique cards must be present)
shuffled_card_set = set(str(card) for card in default_deck.cards)
assert shuffled_card_set == original_card_set
def test_card_dealing(default_deck): def test_card_dealing(default_deck):
"""Tests if the a card is correctly removed from the deck.""" """Tests if the a card is correctly removed from the deck."""

12
tests/test_hand.py Normal file
View File

@@ -0,0 +1,12 @@
import pytest
from pyjack.hand import Hand
@pytest.fixture
def default_hand():
my_hand = Hand()
return my_hand
def test_adding_card_to_hand(default_hand):
default_hand.add_card("diamonds","2")