View Javadoc
1   /*
2    * Licensed to the Hipparchus project under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The Hipparchus project licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.hipparchus.analysis.differentiation;
19  
20  import org.hipparchus.dfp.Dfp;
21  import org.hipparchus.dfp.DfpField;
22  import org.hipparchus.random.RandomGenerator;
23  import org.hipparchus.random.Well19937a;
24  import org.hipparchus.util.FastMath;
25  import org.junit.jupiter.api.Test;
26  
27  import static org.junit.jupiter.api.Assertions.assertEquals;
28  import static org.junit.jupiter.api.Assertions.assertTrue;
29  
30  /**
31   * Test for class {@link FieldUnivariateDerivative2} on {@link Dfp}.
32   */
33  class FieldUnivariateDerivative2DfpTest extends FieldUnivariateDerivative2AbstractTest<Dfp> {
34  
35      private static final DfpField FIELD = new DfpField(25);
36  
37      @Override
38      protected DfpField getValueField() {
39          return FIELD;
40      }
41  
42      @Test
43      public void testHashcode() {
44          assertEquals(-1300667743, build(2, 1, 4).hashCode());
45      }
46  
47      @Override
48      @Test
49      public void testLinearCombinationReference() {
50          doTestLinearCombinationReference(x -> build(x), 5.0e-9, 4.212e-9);
51      }
52  
53      @Override
54      @Test
55      public void testUlp() {
56          final RandomGenerator random = new Well19937a(0x36d4f8862421e0e4l);
57          for (int i = -300; i < 300; ++i) {
58              final double x = FastMath.scalb(2.0 * random.nextDouble() - 1.0, i);
59              assertTrue(FastMath.ulp(x) >= build(x).ulp().getReal());
60          }
61      }
62  
63      @Override
64      @Test
65      public void testUlpVsDS() {
66          // skipped as Dfp is much higher accuracy than double
67      }
68  
69  }