Skip to content

Commit 1a7c930

Browse files
committed
test: add edge-case tests for empty annotation comparisons
Cover three boundary scenarios that previously raised ZeroDivisionError: - Empty reference, non-empty test → sensitivity=NaN, PPV=0.0 - Non-empty reference, empty test → sensitivity=0.0, PPV=NaN - Both empty → both NaN
1 parent 49905a2 commit 1a7c930

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/test_processing.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,33 @@ def test_xqrs(self):
199199

200200
assert comparitor.sensitivity > 0.99
201201
assert comparitor.positive_predictivity > 0.99
202+
203+
def test_compare_annotations_empty_ref(self):
204+
"""When reference annotations are empty, sensitivity should be NaN."""
205+
import math
206+
207+
comparitor = processing.compare_annotations(
208+
np.array([]), np.array([10, 20, 30]), 5
209+
)
210+
assert math.isnan(comparitor.sensitivity)
211+
assert comparitor.positive_predictivity == 0.0
212+
213+
def test_compare_annotations_empty_test(self):
214+
"""When test annotations are empty, PPV should be NaN."""
215+
import math
216+
217+
comparitor = processing.compare_annotations(
218+
np.array([10, 20, 30]), np.array([]), 5
219+
)
220+
assert comparitor.sensitivity == 0.0
221+
assert math.isnan(comparitor.positive_predictivity)
222+
223+
def test_compare_annotations_both_empty(self):
224+
"""When both annotation arrays are empty, both metrics should be NaN."""
225+
import math
226+
227+
comparitor = processing.compare_annotations(
228+
np.array([]), np.array([]), 5
229+
)
230+
assert math.isnan(comparitor.sensitivity)
231+
assert math.isnan(comparitor.positive_predictivity)

0 commit comments

Comments
 (0)