def noNextMovesTest(kboard, coordinates): for coordinate in coordinates[1:]: kboard.mark(coordinate, "x") logger.info("board before moves\n%s", kboard) wknight = Knight(coordinates[0], kboard) logger.info("board\n%s", kboard) with pytest.raises(InvalidLocationError) as error: wknight.nextMove() logger.info("knight path=%s", wknight.path) logger.info("board\n%s", wknight.board)
def runUntilNoMovesLeftPopLastPathTest(kboard, coordinateStart): """ Move until no more moves left and then pop the last move off the stack """ wknight = Knight(coordinateStart, kboard) logger.info("wknight start move=%s", wknight.path[-1]) maxrun = 0 #breakpoint() try: while maxrun < 50: try: wknight.nextMove() except NoMoreMovesError: maxrun += 1 wknight._backtrack() except InvalidLocationError: logger.exception("invalid location found") logger.info("board\n%s", wknight.board) logger.info("wknight last move=%s", json.dumps(wknight.path, indent=2, default=str)) logger.info("wknight._pathPop=%s", json.dumps(wknight._pathPop, indent=2, default=str)) assert len(wknight._pathPop) == 1
def knightFirstMoveLoopToRightDownTest(kboard, coordinateStart, coordinateExpected): wknight = Knight(coordinateStart, kboard) location = wknight.nextMove() logger.info("board\n%s", wknight.board) assert wknight.path[-1] == coordinateExpected
def knightMoveDownRightTest(kboard, coordinateStart, coordinateExpected): wknight = Knight(coordinateStart, kboard) location = wknight.downRight() logger.info("board\n%s", wknight.board) assert wknight.path[-1] == coordinateExpected
def instantiateWhiteKnightTest(kboard, startLoc): wknight = Knight(startLoc, kboard) assert isinstance(wknight, Knight) assert wknight.path == [startLoc]