Skip to content

Commit

Permalink
Add unittest for non-empty reference and non-empty prediction with fu…
Browse files Browse the repository at this point in the history
…ll overlap
  • Loading branch information
valosekj committed Mar 6, 2024
1 parent 0dbd013 commit 63b7913
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/test_compute_metrics_reloaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_empty_pred(self):

def test_non_empty_ref_and_pred(self):
"""
Non-empty reference and non-empty prediction
Non-empty reference and non-empty prediction with partial overlap
"""

expected_metrics = {'EmptyPred': False,
Expand All @@ -142,6 +142,32 @@ def test_non_empty_ref_and_pred(self):
# Assert metrics
self.assert_metrics(metrics_dict, expected_metrics)

def test_non_empty_ref_and_pred_with_full_overlap(self):
"""
Non-empty reference and non-empty prediction with full overlap
"""

expected_metrics = {'EmptyPred': False,
'EmptyRef': False,
'dsc': 1.0,
'fbeta': 1.0,
'nsd': 1.0,
'rel_vol_error': 0.0,
'vol_diff': 0.0}

# Create non-empty reference
ref = np.zeros((10, 10, 10))
ref[4:8, 2:5] = 1
self.create_dummy_nii(self.ref_file, ref)
# Create non-empty prediction
pred = np.zeros((10, 10, 10))
pred[4:8, 2:5] = 1
self.create_dummy_nii(self.pred_file, pred)
# Compute metrics
metrics_dict = compute_metrics_single_subject(self.pred_file.name, self.ref_file.name, self.metrics)
# Assert metrics
self.assert_metrics(metrics_dict, expected_metrics)


if __name__ == '__main__':
unittest.main()

0 comments on commit 63b7913

Please sign in to comment.