From d9bc10bc7dba32631fd0cced29ff265b0d13c606 Mon Sep 17 00:00:00 2001 From: AnihilatorGun Date: Mon, 18 Nov 2024 21:48:15 +0300 Subject: [PATCH] test offset_coordinates, test corner cases --- tests/test_convex_hull.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/test_convex_hull.py b/tests/test_convex_hull.py index d2801fe..6677517 100644 --- a/tests/test_convex_hull.py +++ b/tests/test_convex_hull.py @@ -8,6 +8,11 @@ from imops.src._convex_hull import _left_right_bounds, _offset_unique +@pytest.fixture(params=[False, True]) +def offset_coordinates(request): + return request.param + + def test_bounds(): image = np.zeros((100, 100), dtype=bool) image[20:70, 20:90] = np.random.randn(50, 70) > 0.5 @@ -41,15 +46,29 @@ def test_offset(): assert len(coords_ref) == len(unique_rows(np.concatenate((coords, coords_ref), 0))) -def test_convex_hull_image(): +def test_convex_hull_image(offset_coordinates): image = invert(data.horse()) try: - chull_ref = convex_hull_image(image, offset_coordinates=True, include_borders=True) + chull_ref = convex_hull_image(image, offset_coordinates=offset_coordinates, include_borders=True) except TypeError: - chull_ref = convex_hull_image(image, offset_coordinates=True) + chull_ref = convex_hull_image(image, offset_coordinates=offset_coordinates) - chull = convex_hull_image_fast(image, offset_coordinates=True) + chull = convex_hull_image_fast(image, offset_coordinates=offset_coordinates) assert not (chull < image).any() assert not (chull < chull_ref).any() + + +def test_convex_hull_image_cornercases(offset_coordinates): + image = np.zeros((3, 3, 3), dtype=bool) + + with pytest.raises(RuntimeError): + chull = convex_hull_image_fast(image, offset_coordinates=offset_coordinates) + + image = np.zeros((10, 10), dtype=bool) + + with pytest.warns(UserWarning): + chull = convex_hull_image_fast(image, offset_coordinates=offset_coordinates) + + assert (chull == np.zeros_like(chull)).all()