Skip to content

Add unit tests for CostMap - #332

Open
TheSamarthMehta wants to merge 1 commit into
ShisatoYano:mainfrom
TheSamarthMehta:test/cost-map-unit-tests
Open

TheSamarthMehta wants to merge 1 commit into
ShisatoYano:mainfrom
TheSamarthMehta:test/cost-map-unit-tests

Conversation

@TheSamarthMehta

Copy link
Copy Markdown

Summary

Adds unit tests for CostMap (src/components/mapping/cost/cost_map.py). Until now test_cost_grid_map_construction.py only ran the simulation, so nothing checked the cost stored in each grid.

The new test/test_cost_map.py uses a small 10 m x 10 m map with 1 m grids and checks:

  • two points in the same grid with cost_increment=1.0 give that grid a cost of 2, and every other grid stays at 0
  • the cost never goes above max_cost, both in one update_map() call and over many calls
  • set_cost() keeps a value inside the range and clamps values above max_cost and below free_cost
  • get_cost() returns None for positions outside the map, including the far edge

Closes #301
Part of #103

How I checked it works

  • python -m pytest test/test_cost_map.py -v: 8 passed
  • . run_test_suites.sh: 183 passed
  • Broke cost_map.py on purpose to make sure the tests catch it: removing the max_cost cap in update_map(), removing the clamp in set_cost(), and counting each grid only once each made two tests fail.

Images

Tests only, nothing changed under src/, so no images needed.

Book

  • This PR doesn't change code that the book describes, or I updated those pages

Check the cost that CostMap stores in each grid: two points in the
same grid add the cost twice, other grids stay at zero, the cost is
capped at max_cost, set_cost() clamps between free_cost and max_cost,
and get_cost() returns None outside the map.

This branch has not been deployed

No deployments
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.

Unit tests: the cost that CostMap stores in each cell

1 participant