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.Assert;
26  import org.junit.Test;
27  
28  /**
29   * Test for class {@link FieldUnivariateDerivative2} on {@link Dfp}.
30   */
31  public class FieldUnivariateDerivative2DfpTest extends FieldUnivariateDerivative2AbstractTest<Dfp> {
32  
33      private static final DfpField FIELD = new DfpField(25);
34  
35      @Override
36      protected DfpField getValueField() {
37          return FIELD;
38      }
39  
40      @Test
41      public void testHashcode() {
42          Assert.assertEquals(-1300667743, build(2, 1, 4).hashCode());
43      }
44  
45      @Override
46      @Test
47      public void testLinearCombinationReference() {
48          doTestLinearCombinationReference(x -> build(x), 5.0e-9, 4.212e-9);
49      }
50  
51      @Override
52      @Test
53      public void testUlp() {
54          final RandomGenerator random = new Well19937a(0x36d4f8862421e0e4l);
55          for (int i = -300; i < 300; ++i) {
56              final double x = FastMath.scalb(2.0 * random.nextDouble() - 1.0, i);
57              Assert.assertTrue(FastMath.ulp(x) >= build(x).ulp().getReal());
58          }
59      }
60  
61      @Override
62      @Test
63      public void testUlpVsDS() {
64          // skipped as Dfp is much higher accuracy than double
65      }
66  
67  }