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))
Exemple #2
0
 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))
Exemple #6
0
 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))
Exemple #7
0
 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))
Exemple #8
0
 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)
Exemple #9
0
 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))
Exemple #10
0
 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))
Exemple #12
0
 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))
Exemple #13
0
 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)
Exemple #14
0
 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))
Exemple #15
0
 def testFindStartingPointMazeShortestPossibleMazeShouldBeOneTwo(self):
     maze = Maze('mazes/shortest_possible_maze.txt', QueueFrontier())
     self.assertEqual(Point(1, 2), maze._find_starting_point())
Exemple #16
0
 def testFindStartingPointVeryShortMazeShouldOneThree(self):
     maze = Maze('mazes/very_short_maze.txt', QueueFrontier())
     self.assertEqual(Point(1, 3), maze._find_starting_point())
Exemple #17
0
 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)
Exemple #20
0
 def testCalculateCartesanDistanceFromGoalXValueIsOffByNegativeOneYValueIsOffByOneShouldBeTwo(self):
     frontier = GreedyFrontier()
     frontier.set_goal(Point(5, 5))
     self.assertEqual(2, frontier._calculate_cartesan_distance_from_goal(Point(4, 6)))
Exemple #21
0
 def testFindStartingPointMazeWithDeadEndShouldBeTwoSix(self):
     maze = Maze('mazes/maze_with_dead_end.txt', QueueFrontier())
     self.assertEqual(Point(2, 6), maze._find_starting_point())
Exemple #22
0
 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))
Exemple #23
0
 def testFindGoalMazeWithTurnShouldBeThreeOne(self):
     maze = Maze('mazes/maze_with_turn.txt', QueueFrontier())
     self.assertEqual(Point(3, 1), maze._find_goal())
Exemple #24
0
 def testFindGoalMazeShortestPossibleMazeShouldBeOneOne(self):
     maze = Maze('mazes/shortest_possible_maze.txt', QueueFrontier())
     self.assertEqual(Point(1, 1), maze._find_goal())
Exemple #25
0
 def testFindStartingPointMazeWithTurnShouldBeOneSeven(self):
     maze = Maze('mazes/maze_with_turn.txt', QueueFrontier())
     self.assertEqual(Point(1, 7), maze._find_starting_point())
Exemple #26
0
 def testFindGoalMazeWithCycleShouldBeTwoOne(self):
     maze = Maze('mazes/maze_with_cycle.txt', QueueFrontier())
     self.assertEqual(Point(2, 1), maze._find_goal())
Exemple #27
0
 def testDistanceTraveledNoParentsShouldBeZero(self):
     frontier = AStarFrontier()
     frontier.set_goal(Point(1, 1))
     point = Point(2, 2)
     self.assertEqual(0, frontier._distance_traveled(point))
Exemple #28
0
 def testFindGoalVeryShortMazeShouldBeOneOne(self):
     maze = Maze('mazes/very_short_maze.txt', QueueFrontier())
     self.assertEqual(Point(1, 1), maze._find_goal())
Exemple #29
0
 def testCalculateCartesanDistanceFromGoalIsGoalShouldBeZero(self):
     frontier = GreedyFrontier()
     frontier.set_goal(Point(1, 2))
     self.assertEqual(0, frontier._calculate_cartesan_distance_from_goal(Point(1, 2)))
Exemple #30
0
 def testFindStartingPointMazeWithCycleShouldBeTwoSeven(self):
     maze = Maze('mazes/maze_with_cycle.txt', QueueFrontier())
     self.assertEqual(Point(2, 7), maze._find_starting_point())