Skip to content

test: check kd-tree output behavior - #140

Open
kocaemre wants to merge 1 commit into
ShisatoYano:mainfrom
kocaemre:test/kd-tree-output-checks
Open

kocaemre wants to merge 1 commit into
ShisatoYano:mainfrom
kocaemre:test/kd-tree-output-checks

Conversation

@kocaemre

@kocaemre kocaemre commented Oct 4, 2026

Copy link
Copy Markdown

Summary

  • Adds direct kd-tree output tests for issue Add unit tests that check algorithm outputs #103.
  • Checks nearest-neighbor search against a brute-force distance calculation.
  • Checks radius search returns exactly the points inside the radius on deterministic inputs.

Verification

  • RED: python - <<'PY' ... guard failed before the patch with missing output regression tests: test_nearest_neighbor_matches_brute_force, test_radius_search_returns_only_points_within_radius
  • GREEN: .venv/bin/python -m pytest test/test_search_nearest_neighbor_kd_tree.py -q → 3 passed
  • GREEN: .venv/bin/python -m pytest test/test_search_nearest_neighbor_kd_tree.py test/test_search_neighbor_points_kd_tree.py -q → 4 passed
  • GREEN: .venv/bin/python -m py_compile test/test_search_nearest_neighbor_kd_tree.py src/components/search/kd_tree/kd_tree.py src/components/sensors/lidar/scan_point.py
  • GREEN: git diff --check

No user-visible change: this adds regression coverage only.

Closes #103 for the kd-tree component slice.

Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>
@ShisatoYano

Copy link
Copy Markdown
Owner

Thanks a lot for this, @kocaemre! Comparing the kd-tree nearest neighbor against a brute-force search is exactly the kind of output check #103 asks for, the inputs are small and deterministic, and including a point exactly on the radius boundary (r=1.0) is a nice touch — it pins down that the search is inclusive.

A few requests before merging:

  1. Please change "Closes Add unit tests that check algorithm outputs #103" in the description to "Part of Add unit tests that check algorithm outputs #103". Add unit tests that check algorithm outputs #103 is a tracking issue for all components, and GitHub would close it on merge even with the trailing text.
  2. I tried mutating kd_tree.py locally, and two broken versions still pass the new tests: removing the recursion into right_child in _search_nearest_neighbor_candidates, and removing the r >= candidate_dist check in the radius search (no fixture point lies inside the axis-aligned box but outside the circle, e.g. (0.9, 0.9)). Could you add a seeded random case (e.g. np.random.default_rng(0), ~50 points, ~20 query points) that compares both search_nearest_neighbor_point and search_neighbor_points_within_r with brute force for every query? Please keep the existing boundary point too, with a short comment that <= is intended.
  3. Since these are unit tests of the KdTree component rather than of the simulation, could you move them into a new test/test_kd_tree.py with its own header (file name and your name as Author, like test/test_polar_histogram.py) and leave test_search_nearest_neighbor_kd_tree.py as the smoke test?

Minor: a one-line comment on why scan_points.copy() is needed (KdTree sorts the input list in place) would help readers.

Thanks again!

@ShisatoYano

Copy link
Copy Markdown
Owner

Hi @kocaemre, just checking in: are you still working on this? These tests matter even more now: #204 found that the kd-tree search visits every node instead of skipping subtrees, and your brute-force comparison would be the safety net for fixing it.

If there's no update by November 28, I'll close this PR for now. It isn't a rejection: you're welcome to reopen it anytime.

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

Status: Todo

Development

Successfully merging this pull request may close these issues.

Add unit tests that check algorithm outputs

2 participants