Add unit tests for A* path planner (PythonRobotics #123)#1234
Add unit tests for A* path planner (PythonRobotics #123)#1234rsleiti wants to merge 2 commits intoAtsushiSakai:masterfrom
Conversation
| rx, ry = planner.planning(sx, sy, gx, gy) | ||
|
|
||
| # basic sanity checks | ||
| self.assertTrue(len(rx) > 0) |
Check notice
Code scanning / CodeQL
Imprecise assert Note test
There was a problem hiding this comment.
Pull Request Overview
This PR enhances testing coverage for the A* path planner by adding two new unit tests that verify basic path generation functionality and the edge case where the start point equals the goal.
- Added a test to check that a generated path has matching start and end points, regardless of the order returned.
- Added a focused test for the scenario when the start equals the goal, ensuring the path contains exactly that one point.
Comments suppressed due to low confidence (1)
PathPlanning/AStar/test_astar_unit.py:5
- [nitpick] Consider adding docstrings to the test methods for clearer context and future maintainability.
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) | ||
|
|
There was a problem hiding this comment.
[nitpick] If similar obstacle wall setups are used elsewhere, consider refactoring this pattern into a helper function to improve code reuse.
| 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) | |
| def generate_u_shaped_obstacles(self): | |
| 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) | |
| return ox, oy | |
| def test_basic_path(self): | |
| # create simple U-shaped obstacle walls | |
| ox, oy = self.generate_u_shaped_obstacles() |
| from PathPlanning.AStar.a_star import AStarPlanner | ||
|
|
||
|
|
||
| class TestAStar(unittest.TestCase): |
There was a problem hiding this comment.
@rsleiti There is already test file for AStar code. Please move this test code into this file.
https://github.com/AtsushiSakai/PythonRobotics/blob/master/tests/test_a_star.py
What does this implement/fix?
This pull request adds two
unittesttest cases for the A* path planner inPathPlanning/AStar/a_star.py. The tests check basic path generation and the edge case where the start equals the goal.Why is this useful?
This improves testing coverage for a core algorithm in the PythonRobotics repository. It helps ensure the planner behaves correctly after future changes.
Checklist:
python3 -m PathPlanning.AStar.test_astar_unit