def testFrontierAddPointToEmptyPointsListShouldBeLengthOne(self): frontier = Frontier() self.assertEqual([], frontier._points) self.assertEqual(0, len(frontier._points)) frontier.add_point(Point(3, 4)) self.assertEqual([Point(3, 4)], frontier._points) self.assertEqual(1, len(frontier._points))
def testDistanceTraveledMultipleParentsShouldBeTwo(self): frontier = AStarFrontier() frontier.set_goal(Point(1, 1)) point1 = Point(2, 2) point2 = Point(3, 3, point1) point3 = Point(4, 4, point2) self.assertEqual(2, frontier._distance_traveled(point3))
def testFrontierAddPointToPointListWithOneShouldBeLengthTwo(self): frontier = Frontier() frontier.add_point(Point(3, 4)) self.assertEqual([Point(3, 4)], frontier._points) self.assertEqual(1, len(frontier._points)) frontier.add_point(Point(5, 6)) self.assertEqual([Point(3, 4), Point(5, 6)], frontier._points) self.assertEqual(2, len(frontier._points))
def testFrontierRemovePointListLengthOneShouldBeLengthOne(self): frontier = Frontier() frontier.add_point(Point(3, 4)) self.assertEqual([Point(3, 4)], frontier._points) self.assertEqual(1, len(frontier._points)) frontier.remove_point() self.assertEqual([Point(3, 4)], frontier._points) self.assertEqual(1, len(frontier._points))
def testRemovePointFromPointListLengthOneShouldBeOnlyPoint(self): frontier = QueueFrontier() frontier.add_point(Point(1, 2)) self.assertEqual([Point(1, 2)], frontier._points) self.assertEqual(1, len(frontier._points)) point = frontier.remove_point() self.assertEqual(Point(1, 2), point) self.assertEqual([], frontier._points) self.assertEqual(0, len(frontier._points))
def testRemovePointOnlyOnePointShouldBeOnlyPoint(self): frontier = GreedyFrontier() frontier.set_goal(Point(1, 2)) frontier.add_point(Point(1, 1)) self.assertEqual([Point(1, 1)], frontier._points) self.assertEqual(1, len(frontier._points)) point = frontier.remove_point() self.assertEqual(Point(1, 1), point) self.assertEqual([], frontier._points) self.assertEqual(0, len(frontier._points))
def testRemovePointListHasOnePointShouldBeThatPoint(self): frontier = AStarFrontier() frontier.set_goal(Point(2, 2)) frontier.add_point(Point(1, 2)) self.assertEqual([Point(1, 2)], frontier._points) self.assertEqual(1, len(frontier._points)) point = frontier.remove_point() self.assertEqual(point, Point(1, 2)) self.assertEqual([], frontier._points) self.assertEqual(0, len(frontier._points))
def testAddPointAddingValidPointShouldBeAdded(self): maze = Maze('mazes/linear_maze.txt', QueueFrontier()) self.assertEqual([], maze._frontier._points) self.assertEqual(0, len(maze._frontier._points)) self.assertEqual([], maze._points_explored) self.assertEqual(0, len(maze._points_explored)) maze._add_point(Point(1, 3)) self.assertEqual([Point(1, 3)], maze._frontier._points) self.assertEqual(1, len(maze._frontier._points)) self.assertEqual([Point(1, 3)], maze._points_explored) self.assertEqual([Point(1, 3)], maze._points_explored)
def testRemovePointMultiplePointsShouldBeSecondPoint(self): frontier = GreedyFrontier() frontier.set_goal(Point(2, 3)) frontier.add_point(Point(1, 1)) frontier.add_point(Point(3, 3)) frontier.add_point(Point(5, 5)) self.assertEqual([Point(1, 1), Point(3, 3), Point(5, 5)], frontier._points) self.assertEqual(3, len(frontier._points)) point = frontier.remove_point() self.assertEqual(Point(3, 3), point) self.assertEqual([Point(1, 1), Point(5, 5)], frontier._points) self.assertEqual(2, len(frontier._points))
def testRemovePointListHasMultiplePointsShouldBeSecondPoint(self): frontier = AStarFrontier() frontier.set_goal(Point(3, 3)) point1 = Point(1, 1) point2 = Point(2, 3, point1) point3 = Point(5, 5, point2) frontier.add_point(point1) frontier.add_point(point2) frontier.add_point(point3) self.assertEqual([point1, point2, point3], frontier._points) self.assertEqual(3, len(frontier._points)) point = frontier.remove_point() self.assertEqual(point2, point) self.assertEqual([point1, point3], frontier._points) self.assertEqual(2, len(frontier._points))
def testRemovePointFromPointListMultiplePointsShouldBeFirstPoint(self): frontier = QueueFrontier() frontier.add_point(Point(1, 2)) frontier.add_point(Point(3, 4)) frontier.add_point(Point(5, 6)) self.assertEqual( [Point(1, 2), Point(3, 4), Point(5, 6)], frontier._points) self.assertEqual(3, len(frontier._points)) point = frontier.remove_point() self.assertEqual(Point(1, 2), point) self.assertEqual([Point(3, 4), Point(5, 6)], frontier._points) self.assertEqual(2, len(frontier._points))
def testRemovePointEmptyPointListShouldBeNone(self): frontier = AStarFrontier() frontier.set_goal(Point(1, 2)) self.assertEqual([], frontier._points) self.assertEqual(0, len(frontier._points)) point = frontier.remove_point() self.assertEqual(None, point) self.assertEqual([], frontier._points) self.assertEqual(0, len(frontier._points))
def testAddPointAddingPointAlreadyThereShouldNotBeAdded(self): maze = Maze('mazes/linear_maze.txt', QueueFrontier()) maze._add_point(Point(1, 3)) self.assertEqual([Point(1, 3)], maze._frontier._points) self.assertEqual(1, len(maze._frontier._points)) self.assertEqual([Point(1, 3)], maze._points_explored) self.assertEqual([Point(1, 3)], maze._points_explored) maze._add_point(Point(1, 3)) self.assertEqual([Point(1, 3)], maze._frontier._points) self.assertEqual(1, len(maze._frontier._points)) self.assertEqual([Point(1, 3)], maze._points_explored) self.assertEqual([Point(1, 3)], maze._points_explored)
def testAddPointAddWallTileShouldNotBeAdded(self): maze = Maze('mazes/linear_maze.txt', QueueFrontier()) self.assertNotEqual(None, maze._frontier) self.assertEqual([], maze._frontier._points) self.assertEqual(0, len(maze._frontier._points)) self.assertEqual([], maze._points_explored) self.assertEqual(0, len(maze._points_explored)) maze._add_point(Point(0, 0)) self.assertEqual([], maze._frontier._points) self.assertEqual(0, len(maze._frontier._points)) self.assertEqual([], maze._points_explored) self.assertEqual(0, len(maze._points_explored))
def testFindStartingPointMazeShortestPossibleMazeShouldBeOneTwo(self): maze = Maze('mazes/shortest_possible_maze.txt', QueueFrontier()) self.assertEqual(Point(1, 2), maze._find_starting_point())
def testFindStartingPointVeryShortMazeShouldOneThree(self): maze = Maze('mazes/very_short_maze.txt', QueueFrontier()) self.assertEqual(Point(1, 3), maze._find_starting_point())
def testFindGoalLinearMazeShouldBeOneOne(self): maze = Maze('mazes/linear_maze.txt', QueueFrontier()) self.assertEqual(Point(1, 1), maze._find_goal())
def testFrontierSetGoalHadGoalHasNewGoal(self): frontier = Frontier() frontier.set_goal(Point(1, 2)) self.assertEqual(Point(1, 2), frontier._goal) frontier.set_goal(Point(3, 4)) self.assertEqual(Point(3, 4), frontier._goal)
def testFrontierSetGoalHadNoGoalGivenGoal(self): frontier = Frontier() frontier.set_goal(Point(1, 2)) self.assertEqual(Point(1, 2), frontier._goal)
def testCalculateCartesanDistanceFromGoalXValueIsOffByNegativeOneYValueIsOffByOneShouldBeTwo(self): frontier = GreedyFrontier() frontier.set_goal(Point(5, 5)) self.assertEqual(2, frontier._calculate_cartesan_distance_from_goal(Point(4, 6)))
def testFindStartingPointMazeWithDeadEndShouldBeTwoSix(self): maze = Maze('mazes/maze_with_dead_end.txt', QueueFrontier()) self.assertEqual(Point(2, 6), maze._find_starting_point())
def testDistanceTraveledOneParentShouldBeOne(self): frontier = AStarFrontier() frontier.set_goal(Point(1, 1)) point = Point(2, 2, Point(3, 3)) self.assertEqual(1, frontier._distance_traveled(point))
def testFindGoalMazeWithTurnShouldBeThreeOne(self): maze = Maze('mazes/maze_with_turn.txt', QueueFrontier()) self.assertEqual(Point(3, 1), maze._find_goal())
def testFindGoalMazeShortestPossibleMazeShouldBeOneOne(self): maze = Maze('mazes/shortest_possible_maze.txt', QueueFrontier()) self.assertEqual(Point(1, 1), maze._find_goal())
def testFindStartingPointMazeWithTurnShouldBeOneSeven(self): maze = Maze('mazes/maze_with_turn.txt', QueueFrontier()) self.assertEqual(Point(1, 7), maze._find_starting_point())
def testFindGoalMazeWithCycleShouldBeTwoOne(self): maze = Maze('mazes/maze_with_cycle.txt', QueueFrontier()) self.assertEqual(Point(2, 1), maze._find_goal())
def testDistanceTraveledNoParentsShouldBeZero(self): frontier = AStarFrontier() frontier.set_goal(Point(1, 1)) point = Point(2, 2) self.assertEqual(0, frontier._distance_traveled(point))
def testFindGoalVeryShortMazeShouldBeOneOne(self): maze = Maze('mazes/very_short_maze.txt', QueueFrontier()) self.assertEqual(Point(1, 1), maze._find_goal())
def testCalculateCartesanDistanceFromGoalIsGoalShouldBeZero(self): frontier = GreedyFrontier() frontier.set_goal(Point(1, 2)) self.assertEqual(0, frontier._calculate_cartesan_distance_from_goal(Point(1, 2)))
def testFindStartingPointMazeWithCycleShouldBeTwoSeven(self): maze = Maze('mazes/maze_with_cycle.txt', QueueFrontier()) self.assertEqual(Point(2, 7), maze._find_starting_point())