aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2022-06-29 14:32:57 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2022-06-29 14:33:03 +0200
commit080ef02ab7abc46eae1e2a550d26fdcb6c87450f (patch)
treee264c121d1672bde3525169402784ef58027a7ba /tests
parent15faec71e4c3e972c522d6b0c81fe0b1ec7f7811 (diff)
downloadimago-080ef02ab7abc46eae1e2a550d26fdcb6c87450f.tar.gz
imago-080ef02ab7abc46eae1e2a550d26fdcb6c87450f.zip
Updated some tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_enums.py15
-rw-r--r--tests/test_gameBoard.py20
-rw-r--r--tests/test_parseHelpers.py63
3 files changed, 66 insertions, 32 deletions
diff --git a/tests/test_enums.py b/tests/test_enums.py
new file mode 100644
index 0000000..73f4009
--- /dev/null
+++ b/tests/test_enums.py
@@ -0,0 +1,15 @@
+"""Tests for enums module."""
+
+import unittest
+
+from imago.data.enums import Player
+
+class TestEnums(unittest.TestCase):
+ """Test parseHelpers module."""
+
+ def testOtherPlayer(self):
+ """Test method to get the other player"""
+
+ self.assertEqual(Player.otherPlayer(Player.BLACK), Player.WHITE)
+ self.assertEqual(Player.otherPlayer(Player.WHITE), Player.BLACK)
+ self.assertEqual(Player.otherPlayer(''), Player.EMPTY)
diff --git a/tests/test_gameBoard.py b/tests/test_gameBoard.py
index 3a4d5a0..8a7b127 100644
--- a/tests/test_gameBoard.py
+++ b/tests/test_gameBoard.py
@@ -10,20 +10,33 @@ TEST_BOARD_SIZE = 19
class TestGameBoard(unittest.TestCase):
"""Test gameBoard module."""
- def testGetGroupLiberties(self):
- """Test calculation of group liberties."""
+ def testGetGroupCounts(self):
+ """Test calculation of group stones and liberties."""
board = GameBoard(TEST_BOARD_SIZE, TEST_BOARD_SIZE)
#Empty cell liberties
self.assertEqual(board.getGroupLiberties(0,0), set())
self.assertEqual(board.getGroupLibertiesCount(0,0), 0)
- # Lone stone liberties
+ # Lone stone
board.board[3][3] = Player.WHITE
+ self.assertEqual(board.getGroupVertices(3,3),
+ {(3,3)})
+ self.assertEqual(board.getGroupVerticesCount(3,3), 1)
self.assertEqual(board.getGroupLiberties(3,3),
{(2,3), (3,2), (4,3), (3,4)})
self.assertEqual(board.getGroupLibertiesCount(3,3), 4)
+ # L group (don't compute twice liberty inside L)
+ board.board[3][4] = Player.WHITE
+ board.board[2][4] = Player.WHITE
+ self.assertEqual(board.getGroupVertices(3,3),
+ {(3,3), (3,4), (2,4)})
+ self.assertEqual(board.getGroupVerticesCount(3,3), 3)
+ self.assertEqual(board.getGroupLiberties(3,3),
+ {(2,3), (3,2), (4,3), (4, 4), (3,5), (2,5), (1,4)})
+ self.assertEqual(board.getGroupLibertiesCount(3,3), 7)
+
def testIsCellEye(self):
"""Tests the isCellEye method."""
board = GameBoard(TEST_BOARD_SIZE, TEST_BOARD_SIZE)
@@ -101,6 +114,5 @@ class TestGameBoard(unittest.TestCase):
board.board[9][0] = Player.WHITE
self.assertEqual((9, 21), board.score())
-
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_parseHelpers.py b/tests/test_parseHelpers.py
index d03f253..7bbf152 100644
--- a/tests/test_parseHelpers.py
+++ b/tests/test_parseHelpers.py
@@ -13,16 +13,19 @@ class TestParseHelpers(unittest.TestCase):
def testParseMove(self):
"""Test parsing of GtpMove"""
- self.assertEqual(parseHelpers.parseMove(["B"], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.parseMove(["A1"], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.parseMove(["B", "A1", "W"], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
-
+ wrongMoves = [
+ ["B"],
+ ["A1"],
+ ["B", "A1", "W"]
+ ]
+ for move in wrongMoves:
+ self.assertRaises(
+ RuntimeError,
+ parseHelpers.parseMove,
+ move, TEST_BOARD_SIZE
+ )
parsedMove = parseHelpers.parseMove(["B", "t1"], TEST_BOARD_SIZE)
-
targetMove = parseHelpers.GtpMove(Player.BLACK, [18, 18])
self.assertEqual(parsedMove.color, targetMove.color)
self.assertEqual(parsedMove.vertex, targetMove.vertex)
@@ -33,15 +36,19 @@ class TestParseHelpers(unittest.TestCase):
self.assertEqual(parseHelpers.parseColor("B"), Player.BLACK)
self.assertEqual(parseHelpers.parseColor("w"), Player.WHITE)
self.assertEqual(parseHelpers.parseColor("W"), Player.WHITE)
- self.assertEqual(parseHelpers.parseColor("bw"), parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.parseColor("wb"), parseHelpers.ParseCodes.ERROR)
+
+ self.assertRaises(RuntimeError, parseHelpers.parseColor, "bw")
+ self.assertRaises(RuntimeError, parseHelpers.parseColor, "wb")
def testParseVertexWrongInputs(self):
"""Test wrong inputs for parseVertex."""
inputs = ( "a", "1", "1a", "aa1", "a0", "u1", "a"+str(TEST_BOARD_SIZE+1) )
for text in inputs:
- self.assertEqual(parseHelpers.parseVertex(text, TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
+ self.assertRaises(
+ RuntimeError,
+ parseHelpers.parseVertex,
+ text, TEST_BOARD_SIZE
+ )
def testParseVertexCorrectInputs(self):
"""Test correct inputs and their resulting coordinates for parseVertex."""
@@ -85,22 +92,22 @@ class TestParseHelpers(unittest.TestCase):
self.assertEqual(parseHelpers.vertexToString("pass", TEST_BOARD_SIZE), "pass")
- self.assertEqual(parseHelpers.vertexToString([-1,0], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.vertexToString([0,-1], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.vertexToString([-1,-1], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.vertexToString([19,0], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.vertexToString([0,19], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.vertexToString([19,19], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.vertexToString([0], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
- self.assertEqual(parseHelpers.vertexToString([0,0,0], TEST_BOARD_SIZE),
- parseHelpers.ParseCodes.ERROR)
+ wrongVertices = [
+ [-1,0],
+ [0,-1],
+ [-1,-1],
+ [19,0],
+ [0,19],
+ [19,19],
+ [0],
+ [0,0,0]
+ ]
+ for vertex in wrongVertices:
+ self.assertRaises(
+ RuntimeError,
+ parseHelpers.vertexToString,
+ vertex, TEST_BOARD_SIZE
+ )
if __name__ == '__main__':
unittest.main()