Files
blackjack/tests/test_card.py

53 lines
1.2 KiB
Python
Raw Normal View History

2025-10-28 21:04:39 +01:00
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]