Coverage for app/beaverbunch/src/game/card.py: 100.0%
23 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-08-05 15:01 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-08-05 15:01 +0000
1import functools
4@functools.total_ordering
5class Card:
6 """
7 Represents a card in the game with a specific value.
8 """
10 CARD_VALUES = {i: str(i) for i in range(10)}
11 CARD_VALUES.update({10: "PEEK", 11: "SWAP", 12: "DRAW", 50: "END_GAME"})
13 def __init__(self, value: int) -> None:
14 """
15 Initialises a Card instance with a specific value.
17 Args:
18 value (int): The value of the card, must be one of the predefined values.
19 Raises:
20 ValueError: If the value is not one of the predefined card values.
21 """
22 self.value = value
23 if value not in self.CARD_VALUES.keys():
24 raise ValueError(f"Invalid card value: {value}")
26 def __eq__(self, other) -> bool:
27 if isinstance(other, Card):
28 return self.value == other.value
29 return False
31 def __gt__(self, other) -> bool:
32 if isinstance(other, Card):
33 return self.value > other.value
34 return NotImplemented
36 def __hash__(self) -> int:
37 return hash(self.value)
39 def __repr__(self) -> str:
40 return f"Card(value={self.value})"
42 def __str__(self) -> str:
43 return self.CARD_VALUES[self.value]