1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.hipparchus.analysis.differentiation;
19
20 import org.hipparchus.Field;
21 import org.hipparchus.exception.MathIllegalArgumentException;
22 import org.hipparchus.exception.MathRuntimeException;
23 import org.hipparchus.exception.NullArgumentException;
24 import org.hipparchus.analysis.differentiation.DerivativeTest.TestDerivative;
25 import org.hipparchus.util.FastMath;
26 import org.junit.Assert;
27 import org.junit.Test;
28
29 public class FieldDerivativeTest {
30
31 private static final double TOLERANCE = 1e-10;
32
33 @Test
34 public void testGetReal() {
35
36 final double expectedOperation = 0.5;
37 final TestDerivative testDerivative = new TestDerivative(expectedOperation);
38 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
39
40 final double actualOperation = testFieldDerivative.getReal();
41
42 Assert.assertEquals(expectedOperation, actualOperation, 0.);
43 }
44
45 @Test
46 public void testPow() {
47
48 final TestDerivative testDerivative = new TestDerivative(2.);
49 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
50 final TestDerivative testDerivative2 = new TestDerivative(3.);
51 final TestFieldDerivative testFieldDerivative2 = new TestFieldDerivative(testDerivative2);
52
53 final TestFieldDerivative actualOperation = testFieldDerivative.pow(testFieldDerivative2);
54
55 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
56 .pow(testDerivative.getValue(), testDerivative2.getValue())));
57 Assert.assertEquals(expectedOperation.getValue().getValue(), actualOperation.getValue().getValue(), TOLERANCE);
58 }
59
60 @Test
61 public void testLog10() {
62
63 final TestDerivative testDerivative = new TestDerivative(0.5);
64 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
65
66 final TestFieldDerivative actualOperation = testFieldDerivative.log10();
67
68 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
69 .log10(testDerivative.getValue())));
70 Assert.assertEquals(expectedOperation.getValue().getValue(), actualOperation.getValue().getValue(), TOLERANCE);
71 }
72
73 @Test
74 public void testCosh() {
75
76 final TestDerivative testDerivative = new TestDerivative(0.5);
77 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
78
79 final TestFieldDerivative actualOperation = testFieldDerivative.cosh();
80
81 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
82 .cosh(testDerivative.getValue())));
83 Assert.assertEquals(expectedOperation.getValue().getValue(), actualOperation.getValue().getValue(), TOLERANCE);
84 }
85
86 @Test
87 public void testSinh() {
88
89 final TestDerivative testDerivative = new TestDerivative(0.5);
90 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
91
92 final TestFieldDerivative actualOperation = testFieldDerivative.sinh();
93
94 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
95 .sinh(testDerivative.getValue())));
96 Assert.assertEquals(expectedOperation.getValue().getValue(), actualOperation.getValue().getValue(), TOLERANCE);
97 }
98
99 @Test
100 public void testAcos() {
101
102 final TestDerivative testDerivative = new TestDerivative(0.5);
103 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
104
105 final TestFieldDerivative actualOperation = testFieldDerivative.acos();
106
107 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
108 .acos(testDerivative.getValue())));
109 Assert.assertEquals(expectedOperation.getValue().getValue(), actualOperation.getValue().getValue(), TOLERANCE);
110 }
111
112 @Test
113 public void testFloor() {
114
115 final TestDerivative testDerivative = new TestDerivative(0.5);
116 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
117
118 final TestFieldDerivative actualOperation = testFieldDerivative.floor();
119
120 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
121 .floor(testDerivative.getValue())));
122 Assert.assertEquals(expectedOperation.getValue().getValue(), actualOperation.getValue().getValue(), TOLERANCE);
123 }
124
125 @Test
126 public void testCeil() {
127
128 final TestDerivative testDerivative = new TestDerivative(0.5);
129 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
130
131 final TestFieldDerivative actualOperation = testFieldDerivative.ceil();
132
133 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
134 .ceil(testDerivative.getValue())));
135 Assert.assertEquals(expectedOperation.getValue().getValue(), actualOperation.getValue().getValue(), TOLERANCE);
136 }
137
138 @Test
139 public void testRint() {
140
141 final TestDerivative testDerivative = new TestDerivative(0.5);
142 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
143
144 final TestFieldDerivative actualOperation = testFieldDerivative.rint();
145
146 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
147 .rint(testDerivative.getValue())));
148 Assert.assertEquals(expectedOperation.getValue().getValue(), actualOperation.getValue().getValue(), TOLERANCE);
149 }
150
151 @Test
152 public void testSign() {
153
154 final TestDerivative testDerivative = new TestDerivative(0.5);
155 final TestFieldDerivative testFieldDerivative = new TestFieldDerivative(testDerivative);
156
157 final TestFieldDerivative actualOperation = testFieldDerivative.sign();
158
159 final TestFieldDerivative expectedOperation = new TestFieldDerivative(new TestDerivative(FastMath
160 .signum(testDerivative.getValue())));
161 Assert.assertEquals(expectedOperation, actualOperation);
162 }
163
164 private static class TestFieldDerivative implements FieldDerivative<TestDerivative, TestFieldDerivative> {
165
166 private final TestDerivative value;
167
168 TestFieldDerivative (TestDerivative value) {
169 this.value = value;
170 }
171
172 @Override
173 public TestFieldDerivative newInstance(double value) {
174 return newInstance(new TestDerivative(value));
175 }
176
177 @Override
178 public TestFieldDerivative scalb(int n) {
179 return null;
180 }
181
182 @Override
183 public TestFieldDerivative hypot(TestFieldDerivative y) throws MathIllegalArgumentException {
184 return null;
185 }
186
187 @Override
188 public TestFieldDerivative exp() {
189 return newInstance(value.exp());
190 }
191
192 @Override
193 public TestFieldDerivative expm1() {
194 return null;
195 }
196
197 @Override
198 public TestFieldDerivative log() {
199 return newInstance(value.log());
200 }
201
202 @Override
203 public TestFieldDerivative log1p() {
204 return null;
205 }
206
207 @Override
208 public TestFieldDerivative cos() {
209 return null;
210 }
211
212 @Override
213 public TestFieldDerivative sin() {
214 return null;
215 }
216
217 @Override
218 public TestFieldDerivative asin() {
219 return newInstance(value.asin());
220 }
221
222 @Override
223 public TestFieldDerivative atan() {
224 return null;
225 }
226
227 @Override
228 public TestFieldDerivative atan2(TestFieldDerivative x) throws MathIllegalArgumentException {
229 return null;
230 }
231
232 @Override
233 public TestFieldDerivative acosh() {
234 return null;
235 }
236
237 @Override
238 public TestFieldDerivative asinh() {
239 return null;
240 }
241
242 @Override
243 public TestFieldDerivative atanh() {
244 return null;
245 }
246
247 @Override
248 public TestFieldDerivative linearCombination(TestFieldDerivative[] a, TestFieldDerivative[] b) throws MathIllegalArgumentException {
249 return null;
250 }
251
252 @Override
253 public TestFieldDerivative linearCombination(TestFieldDerivative a1, TestFieldDerivative b1, TestFieldDerivative a2, TestFieldDerivative b2) {
254 return null;
255 }
256
257 @Override
258 public TestFieldDerivative linearCombination(TestFieldDerivative a1, TestFieldDerivative b1, TestFieldDerivative a2, TestFieldDerivative b2, TestFieldDerivative a3, TestFieldDerivative b3) {
259 return null;
260 }
261
262 @Override
263 public TestFieldDerivative linearCombination(TestFieldDerivative a1, TestFieldDerivative b1, TestFieldDerivative a2, TestFieldDerivative b2, TestFieldDerivative a3, TestFieldDerivative b3, TestFieldDerivative a4, TestFieldDerivative b4) {
264 return null;
265 }
266
267 @Override
268 public TestFieldDerivative remainder(double a) {
269 return null;
270 }
271
272 @Override
273 public TestFieldDerivative remainder(TestFieldDerivative a) {
274 return null;
275 }
276
277 @Override
278 public TestFieldDerivative copySign(TestFieldDerivative sign) {
279 return null;
280 }
281
282 @Override
283 public TestFieldDerivative abs() {
284 return null;
285 }
286
287 @Override
288 public TestFieldDerivative add(TestFieldDerivative a) throws NullArgumentException {
289 return new TestFieldDerivative(value.add(a.value));
290 }
291
292 @Override
293 public TestFieldDerivative negate() {
294 return new TestFieldDerivative(value.negate());
295 }
296
297 @Override
298 public TestFieldDerivative multiply(TestFieldDerivative a) throws NullArgumentException {
299 return new TestFieldDerivative(value.multiply(a.value));
300 }
301
302 @Override
303 public TestFieldDerivative reciprocal() throws MathRuntimeException {
304 return new TestFieldDerivative(value.reciprocal());
305 }
306
307 @Override
308 public Field<TestFieldDerivative> getField() {
309 return null;
310 }
311
312 @Override
313 public int getFreeParameters() {
314 return 0;
315 }
316
317 @Override
318 public int getOrder() {
319 return 0;
320 }
321
322 @Override
323 public TestDerivative getValue() {
324 return value;
325 }
326
327 @Override
328 public TestDerivative getPartialDerivative(int... orders) throws MathIllegalArgumentException {
329 return null;
330 }
331
332 @Override
333 public TestFieldDerivative newInstance(TestDerivative value) {
334 return new TestFieldDerivative(value);
335 }
336
337 @Override
338 public boolean equals(Object obj) {
339 if (obj instanceof TestFieldDerivative) {
340 return value.equals(((TestFieldDerivative) obj).value);
341 } else {
342 return false;
343 }
344 }
345 }
346
347 }