import sys,unittest
from pathlib import Path
import cv2,numpy as np
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
from phase_hypotheses import translation_hypotheses
class HypothesesTest(unittest.TestCase):
 def test_direction_on_known_translation(self):
  a=np.random.default_rng(42).integers(0,256,(128,128),dtype='uint8');b=cv2.warpAffine(a,np.float32([[1,0,7],[0,1,-5]]),(128,128),borderMode=cv2.BORDER_REFLECT_101);r=translation_hypotheses(a,b,max_shift=32);self.assertEqual((r['peaks'][0]['dx'],r['peaks'][0]['dy']),(7,-5))
 def test_constant_rejected(self):
  a=np.full((128,128),128,dtype='uint8');self.assertEqual(translation_hypotheses(a,a,max_shift=32)['status'],'unidentifiable_constant')
 def test_periodic_scene_has_multiple_peaks(self):
  yy,xx=np.indices((128,128));a=np.rint(128+40*np.cos(2*np.pi*xx/16)+40*np.cos(2*np.pi*yy/16)).astype('uint8');r=translation_hypotheses(a,a,max_shift=32);self.assertGreaterEqual(len(r['peaks']),2)
 def test_invalid_bounds_rejected(self):
  a=np.zeros((128,128),dtype='uint8')
  with self.assertRaises(ValueError):translation_hypotheses(a,a,max_shift=64)
if __name__=='__main__':unittest.main()
