forked from tiyd-python-2015-05/game-of-sticks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sticks.py
59 lines (45 loc) · 1.3 KB
/
test_sticks.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
from sticks import Game, Human, Computer
import nose
def test_set_remove_sticks():
game = Game()
game.set_num_sticks(5)
assert game.sticks == 5
game.remove_sticks(1)
assert game.sticks == 4
def test_set_switch_players():
player1 = Human('Elf')
player2 = Computer()
game = Game()
game.set_players(player1, player2)
assert game.players[0] is player1
assert game.players[1] is player2
if game.current_player is not player1:
game.switch_player()
assert game.current_player is player1
if game.current_player is not player2:
game.switch_player()
assert game.current_player is player2
def test_game_is_done():
game = Game()
game.set_num_sticks(5)
assert not game.is_done()
game.set_num_sticks(0)
assert game.is_done()
def test_game_status():
game = Game()
game.set_num_sticks(5)
player1 = Human('Alf')
player2 = Human('Bertram')
game.set_players(player1, player2)
game.remove_sticks(2)
assert list(game.status()) == [game.current_player.name, 2, 3]
def test_turn():
game = Game()
game.set_num_sticks(5)
player1 = Computer()
player2 = Computer()
game.set_players(player1, player2)
game.turn()
assert 2 <= game.sticks <=4
if __name__ == '__main__':
nose.main()