Skip to content

Commit

Permalink
randomized data test
Browse files Browse the repository at this point in the history
  • Loading branch information
AnihilatorGun committed Dec 2, 2024
1 parent 109fa12 commit 92e50e8
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/test_convex_hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 92e50e8

Please sign in to comment.