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
|
"""Tests for the input/output component."""
import unittest
from imago.data.enums import Player
from imago.gameLogic.gameState import GameState
class TestGameState(unittest.TestCase):
"""Test GameState component."""
def testCurrentPlayer(self):
"""Test simple commands."""
size = 9
state = GameState(size)
self.assertEqual(state.getCurrentPlayer(), Player.BLACK)
self.assertEqual(state.getPlayerCode(), 'B')
state.playMove(0, 0)
self.assertEqual(state.getCurrentPlayer(), Player.WHITE)
self.assertEqual(state.getPlayerCode(), 'W')
def testPlays(self):
"""Test simple commands."""
size = 3
state = GameState(size)
self.assertEqual(state.getBoard().getBoard(),
[
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY]
])
state.playMove(1, 1)
self.assertEqual(state.getBoard().getBoard(),
[
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.BLACK, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY]
])
state.playPass()
self.assertEqual(state.getBoard().getBoard(),
[
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.BLACK, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY]
])
state.undo()
self.assertEqual(state.getBoard().getBoard(),
[
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.BLACK, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY]
])
state.undo()
self.assertEqual(state.getBoard().getBoard(),
[
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY]
])
state.passForPlayer(Player.WHITE)
self.assertEqual(state.getBoard().getBoard(),
[
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY]
])
self.assertFalse(state.playMove(-1, -1))
self.assertEqual(state.getBoard().getBoard(),
[
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY],
[Player.EMPTY, Player.EMPTY, Player.EMPTY]
])
state.lastMove = None
self.assertEqual(state.getCurrentPlayer(), Player.BLACK)
self.assertRaises(RuntimeError, state.playMove, 0, 0)
if __name__ == '__main__':
unittest.main()
|