-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path_test_celmec.py
192 lines (148 loc) · 5.62 KB
/
_test_celmec.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Copyright 2020-2025 Francesco Biscani ([email protected]), Dario Izzo ([email protected])
#
# This file is part of the heyoka.py library.
#
# This Source Code Form is subject to the terms of the Mozilla
# Public License v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
import unittest as _ut
class kepE_test_case(_ut.TestCase):
def test_expr(self):
from . import kepE, diff, make_vars, sin, cos, core
from .core import _ppc_arch
import numpy as np
x, y = make_vars("x", "y")
# Try a few overloads.
kepE(x, y)
kepE(0.1, y)
kepE(e=x, M=0.2)
self.assertEqual(
diff(kepE(x, y), x), sin(kepE(x, y)) / (1.0 - x * cos(kepE(x, y)))
)
self.assertEqual(diff(kepE(x, y), y), 1.0 / (1.0 - x * cos(kepE(x, y))))
# noconvert() behaviour.
with self.assertRaises(TypeError) as cm:
kepE(23, x)
with self.assertRaises(TypeError) as cm:
kepE(x, 23)
if not _ppc_arch:
self.assertEqual(
diff(kepE(x, np.longdouble("1.1")), x),
sin(kepE(x, np.longdouble("1.1")))
/ (1.0 - x * cos(kepE(x, np.longdouble("1.1")))),
)
self.assertEqual(
diff(kepE(np.longdouble("1.1"), y), y),
1.0 / (1.0 - np.longdouble("1.1") * cos(kepE(np.longdouble("1.1"), y))),
)
kepE(np.longdouble(0.1), y)
kepE(x, np.longdouble(0.2))
with self.assertRaises(TypeError) as cm:
kepE(0.1, np.longdouble("1.1"))
self.assertTrue(
"At least one of the arguments of kepE() must be an expression"
in str(cm.exception)
)
with self.assertRaises(TypeError) as cm:
kepE(0.1, 0.2)
self.assertTrue(
"At least one of the arguments of kepE() must be an expression"
in str(cm.exception)
)
if not hasattr(core, "real128"):
return
from .core import real128
self.assertEqual(
diff(kepE(x, real128("1.1")), x),
sin(kepE(x, real128("1.1"))) / (1.0 - x * cos(kepE(x, real128("1.1")))),
)
self.assertEqual(
diff(kepE(real128("1.1"), y), y),
1.0 / (1.0 - real128("1.1") * cos(kepE(real128("1.1"), y))),
)
class kepF_test_case(_ut.TestCase):
def test_expr(self):
from . import kepF, make_vars, core
from .core import _ppc_arch
import numpy as np
x, y, z = make_vars("x", "y", "z")
# Try a few overloads.
kepF(x, y, z)
kepF(0.1, y, z)
kepF(h=0.1, k=0.2, lam=z)
# noconvert() behaviour.
with self.assertRaises(TypeError) as cm:
kepF(23, x, y)
with self.assertRaises(TypeError) as cm:
kepF(x, 23, y)
with self.assertRaises(TypeError) as cm:
kepF(x, y, 23)
if not _ppc_arch:
kepF(x, y, np.longdouble("1.1"))
kepF(x, np.longdouble(".1"), np.longdouble("1.1"))
with self.assertRaises(TypeError) as cm:
kepF(x, 0.1, np.longdouble("1.1"))
self.assertTrue(
"The numerical arguments of kepF() must be all of the same type"
in str(cm.exception)
)
with self.assertRaises(TypeError) as cm:
kepF(0.1, 0.2, 0.3)
self.assertTrue(
"At least one of the arguments of kepF() must be an expression"
in str(cm.exception)
)
if not hasattr(core, "real128"):
return
from .core import real128
kepF(real128(0.1), y, z)
kepF(real128(0.1), real128(0.2), z)
with self.assertRaises(TypeError) as cm:
kepF(x, 0.1, real128("1.1"))
self.assertTrue(
"The numerical arguments of kepF() must be all of the same type"
in str(cm.exception)
)
class kepDE_test_case(_ut.TestCase):
def test_expr(self):
from . import kepDE, make_vars, core
from .core import _ppc_arch
import numpy as np
x, y, z = make_vars("x", "y", "z")
# Try a few overloads.
kepDE(x, y, z)
kepDE(0.1, y, z)
kepDE(s0=0.1, c0=0.2, DM=z)
# noconvert() behaviour.
with self.assertRaises(TypeError) as cm:
kepDE(23, x, y)
with self.assertRaises(TypeError) as cm:
kepDE(x, 23, y)
with self.assertRaises(TypeError) as cm:
kepDE(x, y, 23)
if not _ppc_arch:
kepDE(x, y, np.longdouble("1.1"))
kepDE(x, np.longdouble(".1"), np.longdouble("1.1"))
with self.assertRaises(TypeError) as cm:
kepDE(x, 0.1, np.longdouble("1.1"))
self.assertTrue(
"The numerical arguments of kepDE() must be all of the same type"
in str(cm.exception)
)
with self.assertRaises(TypeError) as cm:
kepDE(0.1, 0.2, 0.3)
self.assertTrue(
"At least one of the arguments of kepDE() must be an expression"
in str(cm.exception)
)
if not hasattr(core, "real128"):
return
from .core import real128
kepDE(real128(0.1), y, z)
kepDE(real128(0.1), real128(0.2), z)
with self.assertRaises(TypeError) as cm:
kepDE(x, 0.1, real128("1.1"))
self.assertTrue(
"The numerical arguments of kepDE() must be all of the same type"
in str(cm.exception)
)