Test that KD-Tree is built correctly. Cases: - Empty points list. - Positive depth value. - Negative depth value.
(num_points, cube_size, num_dimensions, depth, expected_result)
| 24 | ], |
| 25 | ) |
| 26 | def test_build_kdtree(num_points, cube_size, num_dimensions, depth, expected_result): |
| 27 | """ |
| 28 | Test that KD-Tree is built correctly. |
| 29 | |
| 30 | Cases: |
| 31 | - Empty points list. |
| 32 | - Positive depth value. |
| 33 | - Negative depth value. |
| 34 | """ |
| 35 | points = ( |
| 36 | hypercube_points(num_points, cube_size, num_dimensions).tolist() |
| 37 | if num_points > 0 |
| 38 | else [] |
| 39 | ) |
| 40 | |
| 41 | kdtree = build_kdtree(points, depth=depth) |
| 42 | |
| 43 | if expected_result is None: |
| 44 | # Empty points list case |
| 45 | assert kdtree is None, f"Expected None for empty points list, got {kdtree}" |
| 46 | else: |
| 47 | # Check if root node is not None |
| 48 | assert kdtree is not None, "Expected a KDNode, got None" |
| 49 | |
| 50 | # Check if root has correct dimensions |
| 51 | assert len(kdtree.point) == num_dimensions, ( |
| 52 | f"Expected point dimension {num_dimensions}, got {len(kdtree.point)}" |
| 53 | ) |
| 54 | |
| 55 | # Check that the tree is balanced to some extent (simplistic check) |
| 56 | assert isinstance(kdtree, KDNode), ( |
| 57 | f"Expected KDNode instance, got {type(kdtree)}" |
| 58 | ) |
| 59 | |
| 60 | |
| 61 | def test_nearest_neighbour_search(): |
nothing calls this directly
no test coverage detected