-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-game-state.py
75 lines (69 loc) · 2.3 KB
/
test-game-state.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import unittest
from domino_game_analyzer import GameState, PlayerPosition, DominoTile
class TestGameState(unittest.TestCase):
def test_is_game_over_empty_hand(self):
# Test when a player has an empty hand
hands = [
[], # South (empty hand)
[DominoTile(1, 2)],
[DominoTile(3, 4)],
[DominoTile(5, 6)]
]
state = GameState(
player_hands=tuple(frozenset(hand) for hand in hands),
current_player=PlayerPosition.SOUTH,
left_end=1,
right_end=6,
consecutive_passes=0
)
self.assertTrue(state.is_game_over())
def test_is_game_over_all_players_have_tiles(self):
# Test when all players still have tiles
hands = [
[DominoTile(0, 1)],
[DominoTile(1, 2)],
[DominoTile(3, 4)],
[DominoTile(5, 6)]
]
state = GameState(
player_hands=tuple(frozenset(hand) for hand in hands),
current_player=PlayerPosition.SOUTH,
left_end=1,
right_end=6,
consecutive_passes=0
)
self.assertFalse(state.is_game_over())
def test_is_game_over_consecutive_passes(self):
# Test when there have been 4 consecutive passes
hands = [
[DominoTile(0, 1)],
[DominoTile(1, 2)],
[DominoTile(3, 4)],
[DominoTile(5, 6)]
]
state = GameState(
player_hands=tuple(frozenset(hand) for hand in hands),
current_player=PlayerPosition.SOUTH,
left_end=1,
right_end=6,
consecutive_passes=4
)
self.assertTrue(state.is_game_over())
def test_is_game_over_less_than_four_passes(self):
# Test when there have been less than 4 consecutive passes
hands = [
[DominoTile(0, 1)],
[DominoTile(1, 2)],
[DominoTile(3, 4)],
[DominoTile(5, 6)]
]
state = GameState(
player_hands=tuple(frozenset(hand) for hand in hands),
current_player=PlayerPosition.SOUTH,
left_end=1,
right_end=6,
consecutive_passes=3
)
self.assertFalse(state.is_game_over())
if __name__ == '__main__':
unittest.main()