From e4c4bc311023412722a3aab3e481914535db2901 Mon Sep 17 00:00:00 2001 From: Robby Sleiti <167654950+rsleiti@users.noreply.github.com> Date: Mon, 9 Jun 2025 21:42:22 -0400 Subject: [PATCH 1/2] Add files via upload From 3839489cd42188db0e560253c3e344c8952d53ab Mon Sep 17 00:00:00 2001 From: Robby Sleiti <167654950+rsleiti@users.noreply.github.com> Date: Mon, 9 Jun 2025 21:43:10 -0400 Subject: [PATCH 2/2] Add files via upload --- PathPlanning/AStar/__init__.py | 0 PathPlanning/AStar/test_astar_unit.py | 53 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 PathPlanning/AStar/__init__.py create mode 100644 PathPlanning/AStar/test_astar_unit.py diff --git a/PathPlanning/AStar/__init__.py b/PathPlanning/AStar/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/PathPlanning/AStar/test_astar_unit.py b/PathPlanning/AStar/test_astar_unit.py new file mode 100644 index 0000000000..70e56b9f0b --- /dev/null +++ b/PathPlanning/AStar/test_astar_unit.py @@ -0,0 +1,53 @@ +import unittest +from PathPlanning.AStar.a_star import AStarPlanner + + +class TestAStar(unittest.TestCase): + def test_basic_path(self): + # create simple U-shaped obstacle walls + ox = [i for i in range(60)] # bottom wall + oy = [0 for _ in range(60)] + + for i in range(60): # right wall + ox.append(60) + oy.append(i) + + sx = 10.0 # start (x, y) + sy = 10.0 + gx = 50.0 # goal (x, y) + gy = 50.0 + grid_size = 2.0 + robot_radius = 1.0 + + planner = AStarPlanner(ox, oy, grid_size, robot_radius) + rx, ry = planner.planning(sx, sy, gx, gy) + + # basic sanity checks + self.assertTrue(len(rx) > 0) + self.assertEqual(len(rx), len(ry)) + + # the algorithm may return the path in either direction; + # verify the two endpoints match {start, goal} regardless of order + self.assertCountEqual( + {(rx[0], ry[0]), (rx[-1], ry[-1])}, + {(sx, sy), (gx, gy)} + ) + + def test_start_equals_goal(self): + # provide ONE dummy obstacle so min()/max() calls succeed + sx = sy = gx = gy = 10.0 + ox = [sx] + oy = [sy] + grid_size = 1.0 + robot_radius = 1.0 + + planner = AStarPlanner(ox, oy, grid_size, robot_radius) + rx, ry = planner.planning(sx, sy, gx, gy) + + # when start == goal, path should contain exactly that single point + self.assertEqual(len(rx), 1) + self.assertEqual((rx[0], ry[0]), (sx, sy)) + + +if __name__ == '__main__': + unittest.main()