Coverage for tests/test_permMap.py: 27%
44 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-11 00:57 -0700
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-11 00:57 -0700
1import unittest
3import numpy as np
4from numpy.testing import assert_allclose
6import astshim as ast
7from astshim.test import MappingTestCase
10class TestPermMap(MappingTestCase):
12 def test_PermMapMatched(self):
13 """Test a PermMap whose inverse is the inverse of its forward
14 """
15 permmap = ast.PermMap([2, 3, 1], [3, 1, 2])
16 self.assertEqual(permmap.className, "PermMap")
17 self.assertEqual(permmap.nIn, 3)
18 self.assertEqual(permmap.nOut, 3)
20 self.checkBasicSimplify(permmap)
21 self.checkCopy(permmap)
23 indata = np.array([
24 [1.1, -43.5],
25 [2.2, 1309.31],
26 [3.3, 0.005],
27 ])
28 outdata = permmap.applyForward(indata)
29 pred_outdata = np.array([
30 [3.3, 0.005],
31 [1.1, -43.5],
32 [2.2, 1309.31],
33 ])
34 assert_allclose(outdata, pred_outdata)
36 self.checkRoundTrip(permmap, indata)
37 self.checkMappingPersistence(permmap, indata)
39 def test_PermMapUnmatched(self):
40 """Test PermMap with different number of inputs and outputs
41 """
42 permmap = ast.PermMap([2, 1, 3], [3, 1])
43 self.assertEqual(permmap.className, "PermMap")
44 self.assertEqual(permmap.nIn, 3)
45 self.assertEqual(permmap.nOut, 2)
47 indata = np.array([1.1, 2.2, -3.3])
48 outdata = permmap.applyForward(indata)
49 assert_allclose(outdata, [-3.3, 1.1])
51 indata2 = np.array([1.1, 2.2])
52 outdata2 = permmap.applyInverse(indata2)
53 assert_allclose(outdata2, [2.2, 1.1, np.nan], equal_nan=True)
55 self.checkMappingPersistence(permmap, indata)
57 def test_PermMapWithConstants(self):
58 """Test a PermMap with constant values
59 """
60 permmap = ast.PermMap([-2, 1, 3], [2, 1, -1], [75.3, -126.5])
61 self.assertEqual(permmap.className, "PermMap")
62 self.assertEqual(permmap.nIn, 3)
63 self.assertEqual(permmap.nOut, 3)
65 indata = np.array([1.1, 2.2, 3.3])
66 outdata = permmap.applyForward(indata)
67 assert_allclose(outdata, [2.2, 1.1, 75.3])
69 outdata2 = permmap.applyInverse(indata)
70 assert_allclose(outdata2, [-126.5, 1.1, 3.3])
72 self.checkMappingPersistence(permmap, indata)
75if __name__ == "__main__": 75 ↛ 76line 75 didn't jump to line 76, because the condition on line 75 was never true
76 unittest.main()