Files @ f9ab2070bd69
Branch filter:

Location: OneEye/src/tests/testGo.py

Laman
Engine: more tests and fixes
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=[
			[_,_,_,_,_],
			[B,B,B,B,B],
			[W,W,_,B,_],
			[_,_,_,W,W],
			[_,W,_,W,_]
		]
		self.assertTrue(isLegalPosition(board))

	def testIllegal(self):
		board=[
			[_,B,_,_,_],
			[B,W,B,_,_],
			[_,B,_,_,_],
			[_,_,_,_,_],
			[_,_,_,_,_]
		]
		self.assertFalse(isLegalPosition(board))


class TestMove(TestCase):
	def testCapture(self):
		g=Go(3)
		g.load([
			[_,B,_],
			[B,W,_],
			[_,B,_]
		])
		g.toMove=B
		g.doMove(B,1,2)
		self.assertEqual(g.board,[
			[_,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,_]
		])