added tests

This commit is contained in:
2025-10-28 21:04:39 +01:00
parent 2364b6bbca
commit ed494ec8b2
4 changed files with 82 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
[tool.pytest.ini_options]
pythonpath="src"
testpaths="tests"

0
tests/__init__.py Normal file
View File

52
tests/test_card.py Normal file
View File

@@ -0,0 +1,52 @@
import pytest
from pyjack.card import Card
@pytest.fixture
def cards():
cards = [
Card("diamonds", "2"),
Card("hearts", "A"),
Card("clubs", "9"),
Card("spades", "Q"),
]
return cards
@pytest.fixture
def expected_values():
values = [2, 11, 9, 10]
return values
@pytest.fixture
def expected_strings():
strings = [
"2 of diamonds",
"A of hearts",
"9 of clubs",
"Q of spades",
]
return strings
def test_get_value(cards, expected_values):
"""tests if the correct value is returned by the function"""
results = []
for card in cards:
results.append(card.get_value())
# The zip() function takes multiple iterable objects (like lists
# or tuples) and combines them element-wise, creating an iterator
# of tuples. Each tuple contains one element from each input
# iterable at the corresponding index.
# It effectively allows for parallel iteration.
for expected_value, result in zip(expected_values, results):
assert expected_value == result
def test_default_return_value(cards, expected_strings):
"""Tests if the __str__ method returns the correct value"""
assert expected_strings == [card.__str__() for card in cards]

26
tests/test_deck.py Normal file
View File

@@ -0,0 +1,26 @@
import pytest
from pyjack.deck import Deck
@pytest.fixture
def default_deck() -> Deck:
deck = Deck()
return deck
def test_deck_init(default_deck):
"""Tests if the right amount of cards is created"""
assert len(default_deck.cards) == 52
def test_shuffle_deck(default_deck):
"""Tests if the deck is randomized after method call"""
assert default_deck != default_deck.shuffle()
def test_card_dealing(default_deck):
"""Tests if the a card is correctly removed from the deck."""
default_deck.shuffle()
removed_card = default_deck.deal_card()
assert len(default_deck.cards) == 51
assert removed_card is not None