Skip to content

Add unit tests for A* path planner (PythonRobotics #123) #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rsleiti
Copy link

@rsleiti rsleiti commented Jun 10, 2025

What does this implement/fix?

This pull request adds two unittest test cases for the A* path planner in PathPlanning/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:

  • Added meaningful unittests
  • Tests pass with python3 -m PathPlanning.AStar.test_astar_unit

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

assertTrue(a > b) cannot provide an informative message. Using assertGreater(a, b) instead will give more informative messages.
@AtsushiSakai AtsushiSakai requested a review from Copilot June 15, 2025 13:19
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Comment on lines +6 to +14
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)

Copy link
Preview

Copilot AI Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] If similar obstacle wall setups are used elsewhere, consider refactoring this pattern into a helper function to improve code reuse.

Suggested change
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()

Copilot uses AI. Check for mistakes.

from PathPlanning.AStar.a_star import AStarPlanner


class TestAStar(unittest.TestCase):
Copy link
Owner

@AtsushiSakai AtsushiSakai Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants