def testSolveMazeAStarShortestPossibleMazeShouldBeOneExploredTile(self): maze = Maze('mazes/shortest_possible_maze.txt', AStarFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#'], ['#', 'B', '#'], ['#', 'A', '#'], ['#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(1, maze._number_explored_tiles)
def testSolveMazeAStarVeryShortMazeShouldBeTwoExploredTiles(self): maze = Maze('mazes/very_short_maze.txt', AStarFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#'], ['#', 'B', '#'], ['#', 'O', '#'], ['#', 'A', '#'], ['#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(2, maze._number_explored_tiles)
def testSolveMazeStackVeryShortMazeShouldHaveThreeExploredTiles(self): maze = Maze('mazes/very_short_maze.txt', StackFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#'], ['#', 'B', '#'], ['#', 'O', '#'], ['#', 'A', '#'], ['#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(3, maze._number_explored_tiles)
def testSolveMazeAStarLinearMazeShouldHaveFourExploredTiles(self): maze = Maze('mazes/linear_maze.txt', AStarFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#'], ['#', 'B', '#'], ['#', 'O', '#'], ['#', 'O', '#'], ['#', 'O', '#'], ['#', 'A', '#'], ['#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(4, maze._number_explored_tiles)
def testSolveMazeAStarMazeWithDeadEndShouldHaveSixExploredTiles(self): maze = Maze('mazes/maze_with_dead_end.txt', AStarFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#', '#', '#'], ['#', ' ', '#', 'B', '#'], ['#', ' ', '#', 'O', '#'], ['#', ' ', 'O', 'O', '#'], ['#', '#', 'O', '#', '#'], ['#', '#', 'O', '#', '#'], ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(6, maze._number_explored_tiles)
def testSolveMazeAStarMazeWithTurnShouldHaveEightExploredTiles(self): maze = Maze('mazes/maze_with_turn.txt', AStarFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#', '#', '#'], ['#', '#', '#', 'B', '#'], ['#', '#', '#', 'O', '#'], ['#', '#', '#', 'O', '#'], ['#', 'O', 'O', 'O', '#'], ['#', 'O', '#', '#', '#'], ['#', 'O', '#', '#', '#'], ['#', 'A', '#', '#', '#'], ['#', '#', '#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(8, maze._number_explored_tiles)
def testSolveMazeAStarMazeWithCycleShouldHaveTwelveExploredTiles(self): maze = Maze('mazes/maze_with_cycle.txt', AStarFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#', '#', '#'], ['#', '#', 'B', '#', '#'], ['#', '#', 'O', '#', '#'], ['#', 'O', 'O', 'X', '#'], ['#', 'O', '#', 'X', '#'], ['#', 'O', 'O', 'X', '#'], ['#', '#', 'O', '#', '#'], ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(12, maze._number_explored_tiles)
def testSolveMazeGreedyMazeWithMultipleSolutionsShouldHaveFiveExploredTiles( self): maze = Maze('mazes/maze_with_multiple_solutions.txt', GreedyFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', '#'], ['#', ' ', '#', 'B', '#'], ['#', ' ', '#', 'O', '#'], ['#', ' ', 'O', 'O', '#'], ['#', '#', 'O', '#', '#'], ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(5, maze._number_explored_tiles)
def testSolveMazeGreedyMazeWithCycleShouldHaveEightExploredTiles(self): maze = Maze('mazes/maze_with_cycle.txt', GreedyFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#', '#', '#'], ['#', '#', 'B', '#', '#'], ['#', '#', 'O', '#', '#'], ['#', 'O', 'O', ' ', '#'], ['#', 'O', '#', ' ', '#'], ['#', 'O', 'O', ' ', '#'], ['#', '#', 'O', '#', '#'], ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(8, maze._number_explored_tiles)
def testSolveMazeStackMazeWithDeadEndOnRightShouldHaveTenExploredTiles( self): maze = Maze('mazes/maze_with_dead_end_on_right.txt', StackFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#', '#', '#'], ['#', 'B', '#', 'X', '#'], ['#', 'O', '#', 'X', '#'], ['#', 'O', 'O', 'X', '#'], ['#', '#', 'O', '#', '#'], ['#', '#', 'O', '#', '#'], ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(10, maze._number_explored_tiles)
def testSolveMazeAStarMazeWithMultipleSolutionsGoalOnLeftShouldHaveFiveExploredTiles( self): maze = Maze('mazes/maze_with_multiple_solutions_goal_on_left.txt', AStarFrontier()) maze._solve_maze() expected_maze = [['#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', '#'], ['#', 'B', '#', ' ', '#'], ['#', 'O', '#', ' ', '#'], ['#', 'O', 'O', ' ', '#'], ['#', '#', 'O', '#', '#'], ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']] self.assertEqual(expected_maze, maze._maze) self.assertEqual(5, maze._number_explored_tiles)