diff --git a/tests/test_convex_hull.py b/tests/test_convex_hull.py index 4c16033..24c8436 100644 --- a/tests/test_convex_hull.py +++ b/tests/test_convex_hull.py @@ -9,6 +9,10 @@ from imops.src._convex_hull import _left_right_bounds, _offset_unique +np.random.seed(1337) +N_STRESS = 250 + + @pytest.fixture(params=[False, True]) def offset_coordinates(request): return request.param @@ -60,7 +64,26 @@ def test_convex_hull_image(offset_coordinates): assert (chull >= image).all() assert (chull >= chull_ref).all() - assert ((chull > chull_ref).sum() / chull_ref.sum()) < 1e-2 + assert ((chull > chull_ref).sum() / chull_ref.sum()) < 2e-2 + + +def test_convex_hull_image_random(offset_coordinates): + for _ in range(N_STRESS): + image = np.zeros((200, 200), dtype=bool) + + image[30:-30, 20:-40] = np.random.randn(140, 140) > 2 + + try: + chull_ref = convex_hull_image(image, offset_coordinates=offset_coordinates, include_borders=True) + except TypeError: + chull_ref = convex_hull_image(image, offset_coordinates=offset_coordinates) + + chull = convex_hull_image_fast(image, offset_coordinates=offset_coordinates) + + assert (chull >= image).all() + assert (chull >= chull_ref).all() + + assert ((chull > chull_ref).sum() / chull_ref.sum()) < 2e-2 def test_convex_hull_image_non2d(offset_coordinates):