-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_game.py
156 lines (133 loc) · 4.92 KB
/
test_game.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import asyncio
import unittest
from uuid import uuid4
from game.game import Game
from game.mock_socket import MockSocket
from game.player import Player
from game.deck import make_deck
from game.async_test_helper import run_async
class TestGame(unittest.TestCase):
def setUp(self):
self.game = Game()
self.sock = MockSocket(time_delay=0.1)
p = Player(self.sock, uuid4())
self.game.add_player(p)
def test_add_player(self):
self.assertEqual(len(self.game.players), 1)
def test_remove_player(self):
self.game.remove_player(self.sock)
self.assertEqual(len(self.game.players), 0)
def test_deck_exists(self):
self.assertIsNotNone(self.game.deck)
def test_push_all(self):
pass
def test_flip_card(self):
card = run_async(self.game.flip_card)
self.assertIsNotNone(card)
self.assertIsNotNone(card.name)
self.assertIsNotNone(card.value)
def test_run(self):
pass
def test_flip_card_removes_card_from_deck(self):
start_count = len(self.game.deck)
for _ in range(15):
run_async(self.game.flip_card)
end_count = len(self.game.deck)
self.assertNotEqual(start_count, end_count)
self.assertEqual(start_count, end_count+15)
def test_flip_card_eventually_empties_deck(self):
card = True
while card:
card = run_async(self.game.flip_card)
self.assertEqual(len(self.game.deck), 0)
def test_players_can_trade(self):
# sufficient to test the can_trade method on Player object
pass
def test_game_is_ready_to_start_when_enough_players_join(self):
for _ in range(2):
p = Player(MockSocket(time_delay=0.1), uuid4())
self.game.add_player(p)
self.assertTrue(self.game.is_ready)
def test_play(self):
pass
def test_update_global_state(self):
self.assertIsNone(self.game.global_state)
self.game.update_global_state()
self.assertIsNotNone(self.game.global_state)
def test_auction(self):
pass
def test_challenge(self):
pass
def test_has_legal_challenge_with_single_player(self):
self.assertEqual(
self.game.has_legal_challenge(self.game.players[0]),
[]
)
def test_has_legal_challenge_with_two_players(self):
new_player = Player(MockSocket(time_delay=0.1), uuid4())
self.game.add_player(new_player)
horses = [c for c in make_deck() if c.name == 'horse']
for p in self.game.players:
for _ in range(2):
p.cards.append(horses.pop())
self.assertEqual(
self.game.has_legal_challenge(self.game.players[0]),
[new_player]
)
def test_verify_challenge_with_two_cards_each(self):
new_player = Player(MockSocket(time_delay=0.1), uuid4())
self.game.add_player(new_player)
horses = [c for c in make_deck() if c.name == 'horse']
for p in self.game.players:
for _ in range(2):
p.cards.append(horses.pop())
how_many_cards_can_be_challenged = self.game.verify_challenge(
self.game.players[0],
self.game.players[1],
'horse'
)
self.assertEqual(
how_many_cards_can_be_challenged, 2
)
def test_verify_challenge_with_one_card_each(self):
new_player = Player(MockSocket(time_delay=0.1), uuid4())
self.game.add_player(new_player)
horses = [c for c in make_deck() if c.name == 'horse']
for p in self.game.players:
for _ in range(1):
p.cards.append(horses.pop())
how_many_cards_can_be_challenged = self.game.verify_challenge(
self.game.players[0],
self.game.players[1],
'horse'
)
self.assertEqual(
how_many_cards_can_be_challenged, 1
)
def test_verify_challenge_with_no_common_cards(self):
new_player = Player(MockSocket(time_delay=0.1), uuid4())
self.game.add_player(new_player)
horses = [c for c in make_deck() if c.name == 'horse']
dogs = [c for c in make_deck() if c.name == 'dog']
self.game.players[0].cards.append(horses.pop())
self.game.players[1].cards.append(dogs.pop())
horse_challenge = self.game.verify_challenge(
self.game.players[0],
self.game.players[1],
'horse'
)
dog_challenge = self.game.verify_challenge(
self.game.players[0],
self.game.players[1],
'dog'
)
another_animal_challenge = self.game.verify_challenge(
self.game.players[0],
self.game.players[1],
'cow'
)
self.assertFalse(horse_challenge)
self.assertFalse(dog_challenge)
self.assertFalse(another_animal_challenge)
if __name__ == '__main__':
unittest.main()