import unittest from cockpit_grounding.benchmark.metrics import ( bbox_iou, normalized_center_error, point_in_box, ) class MetricsTest(unittest.TestCase): def test_point_in_box_includes_boundary(self) -> None: self.assertTrue(point_in_box((10, 20), (10, 20, 30, 40))) self.assertFalse(point_in_box((9, 20), (10, 20, 30, 40))) def test_bbox_iou(self) -> None: self.assertAlmostEqual( bbox_iou((0, 0, 10, 10), (5, 5, 15, 15)), 25 / 175, ) self.assertEqual(bbox_iou((0, 0, 2, 2), (3, 3, 4, 4)), 0.0) def test_normalized_center_error_uses_image_diagonal(self) -> None: value = normalized_center_error( pred_center=(5, 5), gt_bbox=(0, 0, 0, 0), image_width=10, image_height=10, ) self.assertAlmostEqual(value, 0.5) def test_metrics_reject_invalid_bbox(self) -> None: with self.assertRaisesRegex(ValueError, "satisfy"): bbox_iou((10, 0, 0, 10), (0, 0, 10, 10))