diff --git a/src/tests/testGo.py b/src/tests/testGo.py --- a/src/tests/testGo.py +++ b/src/tests/testGo.py @@ -1,26 +1,27 @@ from unittest import TestCase +from util import BLACK as B,WHITE as W,EMPTY as _ from go.core import isLegalPosition, Go class TestLegal(TestCase): def testLegal(self): board=[ - [0,0,0,0,0], - [1,1,1,1,1], - [-1,-1,0,1,0], - [0,0,0,-1,-1], - [0,-1,0,-1,0] + [_,_,_,_,_], + [B,B,B,B,B], + [W,W,_,B,_], + [_,_,_,W,W], + [_,W,_,W,_] ] self.assertTrue(isLegalPosition(board)) def testIllegal(self): board=[ - [0,1,0,0,0], - [1,-1,1,0,0], - [0,1,0,0,0], - [0,0,0,0,0], - [0,0,0,0,0] + [_,B,_,_,_], + [B,W,B,_,_], + [_,B,_,_,_], + [_,_,_,_,_], + [_,_,_,_,_] ] self.assertFalse(isLegalPosition(board)) @@ -29,19 +30,35 @@ class TestMove(TestCase): def testCapture(self): g=Go(3) g.load([ - [0,1,0], - [1,-1,0], - [0,1,0] + [_,B,_], + [B,W,_], + [_,B,_] ]) - g.toMove=1 - g.doMove(1,1,2) + g.toMove=B + g.doMove(B,1,2) self.assertEqual(g.board,[ - [0,1,0], - [1,0,1], - [0,1,0] + [_,B,_], + [B,_,B], + [_,B,_] ]) g._helper.clear() for row in g._helper._board: for x in row: self.assertEqual(x,0) + + def testUndo(self): + g=Go(3) + g.load([ + [_,B,_], + [B,W,_], + [_,B,_] + ]) + g.toMove=B + g.doMove(B,1,2) + g.undoMove(1,2,((1,1),)) + self.assertEqual(g.board,[ + [_,B,_], + [B,W,_], + [_,B,_] + ])