-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_player.py
61 lines (49 loc) · 2.63 KB
/
test_player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pytest
from dataclasses import FrozenInstanceError
from cartamayor.common.classes import Card, Pile, Player
from cartamayor.common.types import Suit
def test_player_immutability() -> None:
player = Player("First Name")
with pytest.raises(FrozenInstanceError) as _:
player.name = "Second Name" # type: ignore
def test_player_print(player_with_cards: Player) -> None:
assert str(player_with_cards) == (
"Player One: (PRIVATE) Pile[♣2, ♢3, ♡10, ♠A, ♣4], "
"(OPEN) Pile[♢4, ♢5, ♡6, ♠7], "
"(HIDDEN) Pile[♡4, ♢8, ♠10, ♠K]")
assert repr(player_with_cards) == (
"Player(name='Player One', private_cards=Pile(PileLocation.PRIVATE, ["
"Card(label='2', suit=Suit.CLUBS), Card(label='3', suit=Suit.DIAMONDS), "
"Card(label='10', suit=Suit.HEARTS), Card(label='A', suit=Suit.SPADES), "
"Card(label='4', suit=Suit.CLUBS)]), open_cards=Pile(PileLocation.OPEN, ["
"Card(label='4', suit=Suit.DIAMONDS), Card(label='5', suit=Suit.DIAMONDS), "
"Card(label='6', suit=Suit.HEARTS), Card(label='7', suit=Suit.SPADES)]), "
"hidden_cards=Pile(PileLocation.HIDDEN, ["
"Card(label='4', suit=Suit.HEARTS), Card(label='8', suit=Suit.DIAMONDS), "
"Card(label='10', suit=Suit.SPADES), Card(label='K', suit=Suit.SPADES)]))")
def test_source_definition(player_with_cards: Player) -> None:
assert player_with_cards.get_source() == player_with_cards.private_cards
player_with_cards.private_cards.clear()
assert player_with_cards.get_source() == player_with_cards.open_cards
player_with_cards.open_cards.clear()
assert player_with_cards.get_source() == player_with_cards.hidden_cards
def test_playability_of_player_cards(player_with_cards: Player, table_pile: Pile) -> None:
assert player_with_cards.get_playable_cards(table_pile) == {
Card("2", Suit.CLUBS),
Card("10", Suit.HEARTS),
Card("A", Suit.SPADES)
}
player_with_cards.private_cards.clear()
assert player_with_cards.get_playable_cards(table_pile) == {
Card("5", Suit.DIAMONDS),
Card("6", Suit.HEARTS),
Card("7", Suit.SPADES)
}
table_pile.append(Card("9", Suit.CLUBS))
assert player_with_cards.get_playable_cards(table_pile) == set()
player_with_cards.open_cards.clear()
assert len(player_with_cards.get_playable_cards(table_pile)) == 4
table_pile.append(Card("A", Suit.CLUBS))
assert len(player_with_cards.get_playable_cards(table_pile)) == 4
player_with_cards.hidden_cards.remove(Card("10", Suit.SPADES))
assert len(player_with_cards.get_playable_cards(table_pile)) == 3