import unittest
from diatom_pilot.box_matching import box_iou,match_boxes
class TestBoxMatching(unittest.TestCase):
 def test_assignment_avoids_greedy_collision(self):
  refs=[[0,0,10,10],[6,0,16,10]];preds=[[2,0,12,10],[0,0,10,10]];r=match_boxes(refs,preds,.4);self.assertEqual(r['matched'],2);self.assertEqual(len({x['prediction'] for x in r['assignments']}),2)
 def test_empty_and_threshold(self):
  self.assertEqual(match_boxes([[0,0,1,1]],[],.5)['matched'],0);self.assertEqual(box_iou([0,0,0,0],[0,0,0,0]),0.)
  self.assertEqual(match_boxes([[0,0,2,2]],[[1,0,3,2]],1/3)['matched'],1)
 def test_invalid(self):
  with self.assertRaises(ValueError):match_boxes([[1,0,0,1]],[],.5)
  with self.assertRaises(ValueError):match_boxes([],[],1.1)
if __name__=='__main__':unittest.main()
