def test_getCapturedCoord(self): self.assertEquals("a2", CaptureHelper.getCapturedCoord("a1", "a3")) self.assertEquals("a2", CaptureHelper.getCapturedCoord("a3", "a1")) self.assertEquals("b1", CaptureHelper.getCapturedCoord("a1", "c1")) self.assertEquals("b1", CaptureHelper.getCapturedCoord("c1", "a1")) self.assertEquals("b5", CaptureHelper.getCapturedCoord("a4", "c6")) self.assertEquals("b5", CaptureHelper.getCapturedCoord("c6", "a4")) self.assertEquals("d2", CaptureHelper.getCapturedCoord("c1", "e2")) self.assertEquals("d2", CaptureHelper.getCapturedCoord("e2", "c1")) self.assertIsNone(CaptureHelper.getCapturedCoord("a1", "a4")) self.assertIsNone(CaptureHelper.getCapturedCoord("c2", "e6"))
def validate(self, game): board = game.getBoard() #non-empty start coord startCoord = self.coordList[0] if not board.isBall(startCoord): return False, "%s should be occupied with a ball" % startCoord # each next should be empty and there should be a ball captured fromCoord = self.coordList[0] for toCoord in self.coordList[1:]: captureCoord = CaptureHelper.getCapturedCoord(fromCoord, toCoord) if not captureCoord: return False, "not possible to strike from %s to %s" % (fromCoord, toCoord) if not board.isEmpty(toCoord): return False, "%s should be empty" % toCoord if not board.isBall(captureCoord): return False, "%s should be occupied" % captureCoord # next fromCoord = toCoord return True, "move is valid"
def test_CaptureHelper(self): self.assertEquals(CaptureHelper.getCapturedCoord("a1", "a3"), "a2") self.assertEquals(CaptureHelper.getCapturedCoord("b5", "b3"), "b4") self.assertEquals(CaptureHelper.getCapturedCoord("c3", "e3"), "d3") self.assertEquals(CaptureHelper.getCapturedCoord("c3", "a3"), "b3")