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
|
"""Tests for gameMove module."""
import unittest
from imago.data.enums import Player
from imago.gameLogic.gameBoard import GameBoard
from imago.gameLogic.gameMove import GameMove
TEST_BOARD_SIZE = 19
class TestGameMove(unittest.TestCase):
"""Test gameMove module."""
def testAddMove(self):
"""Test adding new moves to existing moves."""
board = GameBoard(TEST_BOARD_SIZE, TEST_BOARD_SIZE)
firstMove = GameMove(board)
self.assertIsNone(firstMove.coords)
secondMove = firstMove.addMoveByCoords(1, 2)
self.assertIsNone(firstMove.coords)
self.assertEqual(secondMove.coords[0], 1)
self.assertEqual(secondMove.coords[1], 2)
thirdMove = secondMove.addMoveByCoords(5, 7)
self.assertIsNone(firstMove.coords)
self.assertIsNone(thirdMove.previousMove.previousMove.coords)
self.assertEqual(secondMove.coords[0], 1)
self.assertEqual(secondMove.coords[1], 2)
self.assertEqual(thirdMove.previousMove.coords[0], 1)
self.assertEqual(thirdMove.previousMove.coords[1], 2)
self.assertEqual(thirdMove.coords[0], 5)
self.assertEqual(thirdMove.coords[1], 7)
self.assertEqual(firstMove
.nextMoves[0]
.nextMoves[0]
.coords[0], 5)
self.assertEqual(firstMove
.nextMoves[0]
.nextMoves[0]
.coords[1], 7)
self.assertEqual(firstMove.board.getBoard()[1][2], Player.EMPTY)
self.assertEqual(secondMove.board.getBoard()[1][2], Player.BLACK)
self.assertEqual(thirdMove.board.getBoard()[1][2], Player.BLACK)
self.assertEqual(firstMove.board.getBoard()[5][7], Player.EMPTY)
self.assertEqual(secondMove.board.getBoard()[5][7], Player.EMPTY)
self.assertEqual(thirdMove.board.getBoard()[5][7], Player.WHITE)
def testGetPlayableVertices(self):
"""Test getting the set of valid moves."""
boardSize = 3
board = GameBoard(boardSize, boardSize)
firstMove = GameMove(board)
self.assertSetEqual(
firstMove.getPlayableVertices(),
set(((0,0), (0,1), (0,2),
(1,0), (1,1), (1,2),
(2,0), (2,1), (2,2)))
)
secondMove = firstMove.addMoveByCoords(1, 2)
self.assertSetEqual(
secondMove.getPlayableVertices(),
set(((0,0), (0,1), (0,2),
(1,0), (1,1),
(2,0), (2,1), (2,2)))
)
if __name__ == '__main__':
unittest.main()
|