Coverage for tests/test_mathMap.py: 22%

41 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-12 02:15 -0700

1import unittest 

2 

3import numpy as np 

4from numpy.testing import assert_allclose 

5 

6import astshim as ast 

7from astshim.test import MappingTestCase 

8 

9 

10class TestMathMap(MappingTestCase): 

11 

12 def test_MathMapInvertible(self): 

13 mathmap = ast.MathMap( 

14 2, 2, 

15 ["r = sqrt(x * x + y * y)", "theta = atan2(y, x)"], 

16 ["x = r * cos(theta)", "y = r * sin(theta)"], 

17 "SimpIF=1, SimpFI=1, Seed=-57") 

18 self.assertEqual(mathmap.className, "MathMap") 

19 self.assertEqual(mathmap.nIn, 2) 

20 self.assertEqual(mathmap.nOut, 2) 

21 

22 self.checkBasicSimplify(mathmap) 

23 self.checkCopy(mathmap) 

24 

25 indata = np.array([ 

26 [1.0, 2.0, 3.0], 

27 [0.0, 1.0, 2.0], 

28 ]) 

29 outdata = mathmap.applyForward(indata) 

30 x = indata[0] 

31 y = indata[1] 

32 r = outdata[0] 

33 theta = outdata[1] 

34 pred_r = np.sqrt(x * x + y * y) 

35 pred_theta = np.arctan2(y, x) 

36 assert_allclose(r, pred_r) 

37 assert_allclose(theta, pred_theta) 

38 

39 self.checkRoundTrip(mathmap, indata) 

40 self.checkMappingPersistence(mathmap, indata) 

41 

42 self.assertEqual(mathmap.seed, -57) 

43 self.assertTrue(mathmap.simpFI) 

44 self.assertTrue(mathmap.simpIF) 

45 

46 def test_MathMapNonInvertible(self): 

47 mathmap = ast.MathMap(2, 1, 

48 ["r = sqrt(x * x + y * y)"], 

49 ["x = r", "y = 0"]) 

50 self.assertEqual(mathmap.className, "MathMap") 

51 self.assertEqual(mathmap.nIn, 2) 

52 self.assertEqual(mathmap.nOut, 1) 

53 

54 with self.assertRaises(AssertionError): 

55 self.checkBasicSimplify(mathmap) 

56 

57 self.assertFalse(mathmap.simpFI) 

58 self.assertFalse(mathmap.simpIF) 

59 

60 indata = np.array([ 

61 [1.0, 2.0, 3.0], 

62 [0.0, 1.0, 2.0], 

63 ]) 

64 self.checkMappingPersistence(mathmap, indata) 

65 

66 

67if __name__ == "__main__": 67 ↛ 68line 67 didn't jump to line 68, because the condition on line 67 was never true

68 unittest.main()