import sys,unittest
from pathlib import Path
import cv2,numpy as np
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
from focal_profiles import focus_profiles
class FocalProfilesTest(unittest.TestCase):
 def test_sharp_edge_has_higher_focus_energy(self):
  sharp=np.zeros((64,64),dtype='uint8');sharp[20:44,20:44]=200;blur=cv2.GaussianBlur(sharp,(0,0),3);m=np.zeros((64,64),dtype=bool);m[10:54,10:54]=True
  values=focus_profiles(np.stack([blur,sharp]),[m])[0];self.assertGreater(values[1],values[0])
 def test_rejects_empty_or_wrong_mask(self):
  with self.assertRaises(ValueError):focus_profiles(np.zeros((2,64,64)),[np.zeros((64,64),dtype=bool)])
  with self.assertRaises(ValueError):focus_profiles(np.zeros((2,64,64)),[np.ones((5,5),dtype=bool)])
if __name__=='__main__':unittest.main()
