import sys,unittest
from pathlib import Path
import cv2,numpy as np
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
from phase_alignment_checked import checked_alignment
class CheckedPhaseTest(unittest.TestCase):
 def test_flat_images_abstain(self):
  a=np.full((128,128),128,dtype='uint8');r=checked_alignment(a,a);self.assertEqual(r['status'],'unidentifiable_constant');self.assertIsNone(r['correction'])
 def test_translated_textured_image_is_tentative(self):
  rng=np.random.default_rng(7);a=rng.integers(0,256,(128,128),dtype='uint8');b=cv2.warpAffine(a,np.float32([[1,0,5],[0,1,-3]]),(128,128));r=checked_alignment(a,b);self.assertEqual(r['status'],'tentative');self.assertAlmostEqual(r['correction'][0],-5,delta=.3);self.assertAlmostEqual(r['correction'][1],3,delta=.3)
 def test_mismatched_shape_rejected(self):
  with self.assertRaises(ValueError):checked_alignment(np.zeros((64,64)),np.zeros((65,64)))
if __name__=='__main__':unittest.main()
