~cpp
import unittest
from Board import *
class BoardTestCase (unittest.TestCase):
def setUp (self):
self.bd = QueenBoard ()
def tearDown (self):
self.bd = None
def testBoardEmpty (self):
self.assertEquals (self.bd.GetData (2,2), 0)
def testSetQueen (self):
self.bd.SetQueen (2,2)
self.assertEquals (self.bd.GetData (2,2) ,1)
def testPrintBoard (self):
self.bd.SetQueen (1,1)
self.bd.SetQueen (2,2)
self.bd.SetQueen (7,7)
self.assertEquals (self.bd.PrintBoard (), '''00000000\n01000000\n00100000\n00000000\n00000000\n00000000\n00000000\n00000001\n''')
def testIsSelftyZone (self):
self.bd.SetQueen (2,2)
self.assertEquals (self.bd.IsSelftyZone (3,3), 0)
self.assertEquals (self.bd.IsSelftyZone (1,5), 1)
def testFindQueenInSameVertical (self):
self.bd.SetQueen (2,2)
self.assertEquals (self.bd.FindQueenInSameVertical (2), 1)
self.assertEquals (self.bd.FindQueenInSameVertical (3), 0)
def testFindQueenInSameHorizonal (self):
self.bd.SetQueen (2,2)
self.assertEquals (self.bd.FindQueenInSameHorizonal (2), 1)
self.assertEquals (self.bd.FindQueenInSameHorizonal (3), 0)
def testFindQueenInSameCrossLeftTopToRightBottom (self):
self.bd.SetQueen (2,2)
self.assertEquals (self.bd.FindQueenInSameCrossLeftTopToRightBottom (3,3), 1)
self.assertEquals (self.bd.FindQueenInSameCrossLeftTopToRightBottom (1,1), 1)
self.assertEquals (self.bd.FindQueenInSameCrossLeftTopToRightBottom (4,1), 0)
def testFindQueenInSameCrossLeftBottomToRightTop (self):
self.bd.SetQueen (2,2)
self.assertEquals (self.bd.FindQueenInSameCrossLeftBottomToRightTop (3,3), 0)
self.assertEquals (self.bd.FindQueenInSameCrossLeftBottomToRightTop (3,1), 1)
self.assertEquals (self.bd.FindQueenInSameCrossLeftBottomToRightTop (1,3), 1)
def testGetFirstCornerInCrossLeftTopToRightBottom (self):
self.assertEquals (self.bd.GetFirstCornerInCrossLeftTopToRightBottom (3,3), (0,0))
self.assertEquals (self.bd.GetFirstCornerInCrossLeftTopToRightBottom (4,3), (1,0))
self.assertEquals (self.bd.GetFirstCornerInCrossLeftTopToRightBottom (1,5), (0,4))
self.assertEquals (self.bd.GetFirstCornerInCrossLeftTopToRightBottom (0,0), (0,0))
def testGetFirstCornerInCrossLeftBottomToRightTop (self):
self.assertEquals (self.bd.GetFirstCornerInCrossLeftBottomToRightTop (2,2), (0,4))
self.assertEquals (self.bd.GetFirstCornerInCrossLeftBottomToRightTop (3,5), (1,7))
self.assertEquals (self.bd.GetFirstCornerInCrossLeftBottomToRightTop (7,7), (7,7))
def testIsAttackableOthers (self):
self.bd.SetQueen (2,2)
self.assertEquals (self.bd.IsAttackableOthers (3,3),1)
self.bd.SetQueen (7,1)
self.assertEquals (self.bd.IsAttackableOthers (7,1),0)
self.assertEquals (self.bd.IsAttackableOthers (4,4),1)
def testEightQueen (self):
## self.bd.EightQueen ()
## if all queen pass the function 'IsAttackableOthers'
self.bd.EightQueen ()
def testGetUnAttackablePositon (self):
self.bd.SetQueen (0,0)
self.assertEquals (self.bd.GetUnAttackablePosition (1), ((2,1),(3,1),(4,1),(5,1),(6,1),(7,1)))
self.assertEquals (self.bd.GetUnAttackablePosition (2), ((1,2),(3,2),(4,2),(5,2),(6,2),(7,2)))
suite = unittest.makeSuite (BoardTestCase, "test")
runner = unittest.TextTestRunner ()
runner.run (suite)