Skip to content

Commit 63be86b

Browse files
committed
Fix P1 bug: test_query_intersections_deterministic should compare unordered collections
The test was using np.array_equal() to compare results byte-for-byte, but query_intersections() returns pairs from an unordered map with parallel execution, so the order is not guaranteed and can vary between invocations or CPU architectures. Fixed by converting results to sets for order-independent comparison, which correctly validates that the same pairs are returned even if the order differs.
1 parent a6a2834 commit 63be86b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tests/unit/test_parallel_configuration.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ def test_query_intersections_scaling(self, PRTree, dim, tree_size):
316316

317317
@pytest.mark.parametrize("PRTree, dim", [(PRTree2D, 2), (PRTree3D, 3)])
318318
def test_query_intersections_deterministic(self, PRTree, dim):
319-
"""Verify that query_intersections returns deterministic results."""
319+
"""Verify that query_intersections returns deterministic results.
320+
321+
Note: The order of pairs is not guaranteed due to unordered map and
322+
parallel execution, so we compare as sets rather than arrays.
323+
"""
320324
np.random.seed(42)
321325
n = 200
322326
idx = np.arange(n)
@@ -331,9 +335,12 @@ def test_query_intersections_deterministic(self, PRTree, dim):
331335
pairs2 = tree.query_intersections()
332336
pairs3 = tree.query_intersections()
333337

334-
# Should be identical
335-
assert np.array_equal(pairs1, pairs2)
336-
assert np.array_equal(pairs2, pairs3)
338+
set1 = set(map(tuple, pairs1))
339+
set2 = set(map(tuple, pairs2))
340+
set3 = set(map(tuple, pairs3))
341+
342+
assert set1 == set2, f"pairs1 and pairs2 differ: {set1 ^ set2}"
343+
assert set2 == set3, f"pairs2 and pairs3 differ: {set2 ^ set3}"
337344

338345
@pytest.mark.parametrize("PRTree, dim", [(PRTree2D, 2), (PRTree3D, 3)])
339346
def test_query_intersections_correctness(self, PRTree, dim):

0 commit comments

Comments
 (0)