Skip to content

AMaharaj16/test-conditions-switch-path-669#743

Closed
AMaharaj16 wants to merge 47 commits into
mainfrom
AMaharaj16/test-conditions-switch-path-669
Closed

AMaharaj16/test-conditions-switch-path-669#743
AMaharaj16 wants to merge 47 commits into
mainfrom
AMaharaj16/test-conditions-switch-path-669

Conversation

@AMaharaj16
Copy link
Copy Markdown
Contributor

@AMaharaj16 AMaharaj16 commented Dec 30, 2025

Refactored the update_if_needed function to improve testability by extracting the metric calculation logic (which combines heading difference cost and path cost) into a separate, testable unit called calculate_metric. Test suite for calculate_metric fully passes. No actual computation changes made.

Also moved test_calculate_desired_heading_and_waypoint_index from test_node_navigate.py to test_local_path.py and added testing for calculate_heading_diff.

Next, I plan to test update_if_needed altogether using a deterministic function that creates OMPLPath mock objects with predetermined paths to enable controlled testing.

…nd heading even though old path is most optimal.
…into AMaharaj16/test-conditions-switch-path-669
…est for improved clarity and robustness in testing.
…s OMPLPath parameters but I can't pick waypoints in OMPLPath. Current solution is to move get_cost back into update_if_needed and pass costs into compare_path_costs where total costs (add heading cost) is calculated and cheapest path returned.
…on, will try to test from here now that I know the issues.
…d passing tests to the function. Heading calculations are good, now I need to look into testing path costs.
@AMaharaj16
Copy link
Copy Markdown
Contributor Author

14 files changed... that's not right lol. I stopped coding on this for a few weeks during finals and I think I committed some files I didn't mean to change after I came back. I will look into fixing this.

Copy link
Copy Markdown
Contributor

@raghumanimehta raghumanimehta left a comment

Choose a reason for hiding this comment

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

Nice work on the PR! Requesting a bunch of refactoring the code before I merge this to the main branch. As soon as you are done with the changes, let me know and move on to the next half of testing.


metric_old = w_h * heading_diff_old_normalized + w_c * old_cost_normalized
metric_new = w_h * heading_diff_new_normalized + w_c * new_cost_normalized
metric_old, metric_new = self.calculate_metric(heading, heading_old_path, heading_new_path,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of returning a tuple of old and new, you can make function reusable such that it doesn't care if you pass the old or new path. You can call compute metric on the old_path and new_path separately to get old and new metric respectively.
For example:

new_metric = calculate_metric(heading_new_normalized, heading_old_normalized)

This function right now is very tightly coupled with the caller. Also, I don't like the assymetric behaviour where we are normalizing the cost outside the function but normalizing the heading inside.

@raghumanimehta raghumanimehta self-requested a review January 26, 2026 04:04
@AMaharaj16
Copy link
Copy Markdown
Contributor Author

AMaharaj16 commented Feb 1, 2026

Don't merge just yet, last test fails every 8-10 test runs. Since the function can have fluctuating outputs, testing boundary cases (improvement threshold) will be quite inconsistent. I think we should either remove the last test or change it so it covers another case such as one with >3 waypoints and ensure it passes consistently. What do you think @raghumanimehta? I can finish it from there onwards.

Also, I have run all other test cases for test_update_if_needed 30-40 times each and they consistently pass. However, it may be worth adding a note to the test function so that if anyone ever sees it fail, they should just rerun it and see it passing once again.

@raghumanimehta raghumanimehta enabled auto-merge (squash) February 1, 2026 07:12
raghumanimehta
raghumanimehta previously approved these changes Feb 1, 2026
Copy link
Copy Markdown
Contributor

@raghumanimehta raghumanimehta left a comment

Choose a reason for hiding this comment

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

The task is yet not complete. Merging because, there are notable improvements in update_if_needed

return True


def create_mock(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this function is strictly going to be used for testing, we can safely move this to the test file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

path Pathfinding team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants