|
10 | 10 | a1 = np.array([[0, 0, 1], [0, 0, 1], [0, 1, 1]])
|
11 | 11 | a2 = np.array([[0], [0], [1]])
|
12 | 12 | a3 = np.array([0, 0, 1]).T
|
| 13 | +a4 = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) |
13 | 14 |
|
14 | 15 | b1 = np.array([[0], [0], [0]])
|
15 | 16 | b2 = np.array([1, -1, 1]).T
|
| 17 | +b3 = np.array([1, 0, 0]).T |
16 | 18 |
|
17 | 19 |
|
18 |
| -a1_b1 = np.array([[0, 0, pi / 4], [0, 0, pi / 4]]) |
19 |
| -a1_b2 = np.array([[3 * pi / 4, 3 * pi / 4, pi / 2], [3 * pi / 4, pi / 2, pi / 2]]) |
| 20 | +a1_b1 = np.array([[0, 0, pi / 4], [0, 0, np.arctan(np.sqrt(2.0))]]) |
| 21 | +a1_b2 = np.array( |
| 22 | + [ |
| 23 | + [3 * pi / 4, 3 * pi / 4, pi / 2], |
| 24 | + [pi / 2 + np.arctan(1.0 / np.sqrt(2)), pi / 2, pi / 2], |
| 25 | + ] |
| 26 | +) |
20 | 27 | a2_b1 = np.array([[0], [0]])
|
21 | 28 | a2_b2 = np.array([[3 * pi / 4], [pi / 2]])
|
22 | 29 | a3_b1 = np.array([[0], [0]])
|
23 | 30 | a3_b2 = np.array([[3 * pi / 4], [pi / 2]])
|
| 31 | +a4_b1 = np.array([[0, pi / 2, 0], [0, pi / 2, pi / 2]]) |
| 32 | +a4_b3 = np.array([[pi, 3 * pi / 4, 0], [pi / 4, pi / 2, 0]]) |
| 33 | +a2_b3 = np.array([[pi], [pi / 4]]) |
| 34 | +a3_b3 = np.array([[pi], [pi / 4]]) |
24 | 35 |
|
25 | 36 |
|
26 | 37 | # for 2-D coordinates
|
|
40 | 51 | c3_d2 = np.array([[0], [pi / 2]])
|
41 | 52 |
|
42 | 53 |
|
43 |
| -class TestAngleFunction(TestCase): |
44 |
| - def test_set_3d(self): |
45 |
| - self.assertTrue(angle_function(a1, b1).all() == a1_b1.all()) |
46 |
| - self.assertTrue(angle_function(a1, b2).all() == a1_b2.all()) |
47 |
| - |
48 |
| - def test_point_3d_1(self): |
49 |
| - self.assertTrue(angle_function(a2, b1).all() == a2_b1.all()) |
50 |
| - self.assertTrue(angle_function(a2, b2).all() == a2_b2.all()) |
51 |
| - |
52 |
| - def test_point_3d_2(self): |
53 |
| - self.assertTrue(angle_function(a3, b1).all() == a3_b1.all()) |
54 |
| - self.assertTrue(angle_function(a3, b2).all() == a3_b2.all()) |
55 |
| - |
56 |
| - def test_set_2d(self): |
57 |
| - self.assertTrue(angle_function(c1, d1).all() == c1_d1.all()) |
58 |
| - self.assertTrue(angle_function(c1, d2).all() == c1_d2.all()) |
59 |
| - |
60 |
| - def test_point_2d_1(self): |
61 |
| - self.assertTrue(angle_function(c2, d1).all() == c2_d1.all()) |
62 |
| - self.assertTrue(angle_function(c2, d2).all() == c2_d2.all()) |
63 |
| - |
64 |
| - def test_point_2d_2(self): |
65 |
| - self.assertTrue(angle_function(c3, d1).all() == c3_d1.all()) |
66 |
| - self.assertTrue(angle_function(c3, d2).all() == c3_d2.all()) |
67 |
| - |
68 |
| - |
69 |
| -def find_error(type_coordinates): |
70 |
| - if type_coordinates == "3-D": |
71 |
| - print("-" * 40) |
72 |
| - print("type_coordinates = 3-D") |
73 |
| - print("-" * 40) |
74 |
| - |
75 |
| - a_range = [a1, a2, a3] |
76 |
| - b_range = [b1, b2] |
77 |
| - a_b_range = [a1_b1, a1_b2, a2_b1, a2_b2, a3_b1, a3_b2] |
78 |
| - |
79 |
| - a_b_index = 0 |
80 |
| - for a in a_range: |
81 |
| - for b in b_range: |
82 |
| - error_azimuth = (angle_function(a, b) - a_b_range[a_b_index])[0] |
83 |
| - error_colatitude = (angle_function(a, b) - a_b_range[a_b_index])[1] |
84 |
| - |
85 |
| - print("for points :") |
86 |
| - print(a) |
87 |
| - print(b) |
88 |
| - print( |
89 |
| - "error in azimuth calculation: {}".format(np.average(error_azimuth)) |
90 |
| - ) |
91 |
| - print( |
92 |
| - "error in colatitude calculation: {}".format( |
93 |
| - np.average(error_colatitude) |
94 |
| - ) |
95 |
| - ) |
96 |
| - print() |
97 |
| - a_b_index += 1 |
98 |
| - |
99 |
| - elif type_coordinates == "2-D": |
100 |
| - print("-" * 40) |
101 |
| - print("type_coordinates = 2-D") |
102 |
| - print("-" * 40) |
103 |
| - |
104 |
| - c_range = [c1, c2, c3] |
105 |
| - d_range = [d1, d2] |
106 |
| - c_d_range = [c1_d1, c1_d2, c2_d1, c2_d2, c3_d1, c3_d2] |
107 |
| - |
108 |
| - c_d_index = 0 |
109 |
| - for c in c_range: |
110 |
| - for d in d_range: |
111 |
| - error_azimuth = (angle_function(c, d) - c_d_range[c_d_index])[0] |
112 |
| - error_colatitude = (angle_function(c, d) - c_d_range[c_d_index])[1] |
113 |
| - |
114 |
| - print("for points :") |
115 |
| - print(c) |
116 |
| - print(d) |
117 |
| - print( |
118 |
| - "error in azimuth calculation: {}".format(np.average(error_azimuth)) |
119 |
| - ) |
120 |
| - print( |
121 |
| - "error in colatitude calculation: {}".format( |
122 |
| - np.average(error_colatitude) |
123 |
| - ) |
124 |
| - ) |
125 |
| - print() |
126 |
| - c_d_index += 1 |
127 |
| - |
128 |
| - |
129 |
| -if __name__ == "__main__": |
130 |
| - find_error("3-D") |
131 |
| - find_error("2-D") |
| 54 | +def test_set_3d(): |
| 55 | + assert np.allclose(angle_function(a1, b1), a1_b1) |
| 56 | + assert np.allclose(angle_function(a1, b2), a1_b2) |
| 57 | + |
| 58 | + |
| 59 | +def test_point_3d_1(): |
| 60 | + assert np.allclose(angle_function(a2, b1), a2_b1) |
| 61 | + assert np.allclose(angle_function(a2, b2), a2_b2) |
| 62 | + assert np.allclose(angle_function(a2, b3), a2_b3) |
| 63 | + |
| 64 | + |
| 65 | +def test_point_3d_2(): |
| 66 | + assert np.allclose(angle_function(a3, b1), a3_b1) |
| 67 | + assert np.allclose(angle_function(a3, b2), a3_b2) |
| 68 | + assert np.allclose(angle_function(a3, b3), a3_b3) |
| 69 | + |
| 70 | + |
| 71 | +def test_point_3d_3(): |
| 72 | + assert np.allclose(angle_function(a4, b1), a4_b1) |
| 73 | + assert np.allclose(angle_function(a4, b3), a4_b3) |
| 74 | + |
| 75 | + |
| 76 | +def test_set_2d(): |
| 77 | + assert np.allclose(angle_function(c1, d1), c1_d1) |
| 78 | + assert np.allclose(angle_function(c1, d2), c1_d2) |
| 79 | + |
| 80 | + |
| 81 | +def test_point_2d_1(): |
| 82 | + assert np.allclose(angle_function(c2, d1), c2_d1) |
| 83 | + assert np.allclose(angle_function(c2, d2), c2_d2) |
| 84 | + |
| 85 | + |
| 86 | +def test_point_2d_2(): |
| 87 | + assert np.allclose(angle_function(c3, d1), c3_d1) |
| 88 | + assert np.allclose(angle_function(c3, d2), c3_d2) |
0 commit comments