Coverage for tests/test_mathMap.py: 26%
41 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-15 09:29 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-15 09:29 +0000
1import unittest
3import numpy as np
4from numpy.testing import assert_allclose
6import astshim as ast
7from astshim.test import MappingTestCase
10class TestMathMap(MappingTestCase):
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)
22 self.checkBasicSimplify(mathmap)
23 self.checkCopy(mathmap)
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)
39 self.checkRoundTrip(mathmap, indata)
40 self.checkMappingPersistence(mathmap, indata)
42 self.assertEqual(mathmap.seed, -57)
43 self.assertTrue(mathmap.simpFI)
44 self.assertTrue(mathmap.simpIF)
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)
54 with self.assertRaises(AssertionError):
55 self.checkBasicSimplify(mathmap)
57 self.assertFalse(mathmap.simpFI)
58 self.assertFalse(mathmap.simpIF)
60 indata = np.array([
61 [1.0, 2.0, 3.0],
62 [0.0, 1.0, 2.0],
63 ])
64 self.checkMappingPersistence(mathmap, indata)
67if __name__ == "__main__": 67 ↛ 68line 67 didn't jump to line 68, because the condition on line 67 was never true
68 unittest.main()