added tests
This commit is contained in:
52
tests/test_card.py
Normal file
52
tests/test_card.py
Normal 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]
|
||||
Reference in New Issue
Block a user