-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_room.py
73 lines (61 loc) · 2.08 KB
/
test_room.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
from room import Room
def test_init():
room = Room()
assert room.players == []
assert room.observers == []
assert room.finished is False
def test_join():
room = Room()
room.join_player('player1')
room.reveal()
room.join_player('player2')
room.join_observer('observer1')
assert {'name': 'player1', 'choice': None} in room.players
assert {'name': 'player2', 'choice': None} in room.players
assert len(room.players) == 2
assert {'name': 'observer1'} in room.observers
assert len(room.observers) == 1
assert not room.finished
def test_leave():
room = Room()
room.join_player('player1')
room.join_player('player2')
room.join_observer('observer1')
room.join_observer('observer2')
room.leave('player1')
room.leave('observer2')
assert {'name': 'player2', 'choice': None} in room.players
assert len(room.players) == 1
assert {'name': 'observer1'} in room.observers
assert len(room.observers) == 1
def test_select():
room = Room()
room.join_player('player1')
room.join_player('player2')
room.join_observer('observer1')
room.select('player1', 'choice1')
assert not room.finished
room.select('player2', 'choice2')
assert room.finished
assert {'name': 'player1', 'choice': 'choice1'} in room.players
assert {'name': 'player2', 'choice': 'choice2'} in room.players
# Select is disabled when voting is finished
room.select('player1', 'choice2')
assert {'name': 'player1', 'choice': 'choice1'} in room.players
assert {'name': 'observer1'} in room.observers
def test_clear():
room = Room()
room.join_player('player1')
room.join_player('player2')
room.join_observer('observer1')
room.select('player1', 'choice1')
room.select('player2', 'choice2')
room.clear()
assert not room.finished
assert {'name': 'player1', 'choice': None} in room.players
assert {'name': 'player2', 'choice': None} in room.players
assert {'name': 'observer1'} in room.observers
def test_reveal():
room = Room()
room.reveal()
assert room.finished