1 /*
2 * Licensed to the Apache Software Foundation (ASF) 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 ASF 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 /*
19 * This is not the original file distributed by the Apache Software Foundation
20 * It has been modified by the Hipparchus project
21 */
22 package org.hipparchus.analysis.integration.gauss;
23
24 import org.hipparchus.util.Binary64;
25 import org.hipparchus.util.Binary64Field;
26 import org.hipparchus.util.FastMath;
27 import org.junit.jupiter.params.ParameterizedTest;
28 import org.junit.jupiter.params.provider.MethodSource;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32
33 /**
34 * Test of the {@link FieldHermiteRuleFactory}.
35 * This parameterized test extends the standard test for Gaussian quadrature
36 * rule, where each monomial is tested in turn.
37 * Parametrization allows to test automatically 0, 1, ... , {@link #MAX_NUM_POINTS}
38 * quadrature rules.
39 *
40 */
41 public class FieldHermiteParametricTest extends FieldGaussianQuadratureAbstractTest {
42 private static final double SQRT_PI = FastMath.sqrt(Math.PI);
43 private static final FieldGaussIntegratorFactory<Binary64> factory = new FieldGaussIntegratorFactory<>(Binary64Field.getInstance());
44
45 /**
46 * The highest order quadrature rule to be tested.
47 */
48 public static final int MAX_NUM_POINTS = 30;
49
50 /**
51 * Returns the collection of parameters to be passed to the constructor of
52 * this class.
53 * Gauss-Hermite quadrature rules of order 1, ..., {@link #MAX_NUM_POINTS}
54 * will be constructed.
55 *
56 * @return the collection of parameters for this parameterized test.
57 */
58 public static Collection<Object[]> getParameters() {
59 final ArrayList<Object[]> parameters = new ArrayList<Object[]>();
60 final int [] numUlps = {
61 10, 10, 10, 10, 20,
62 20, 30, 30, 30, 40,
63 40, 60, 150, 150, 150,
64 150, 150, 150, 150, 200,
65 250, 250, 300, 300, 300,
66 300, 300, 300, 350, 350
67 };
68 for (int k = 1; k <= MAX_NUM_POINTS; k++) {
69 parameters.add(new Object[] { k, 2 * k - 1, Math.ulp(1d), numUlps[k - 1] });
70 }
71 return parameters;
72 }
73
74 @Override
75 public double getExpectedValue(final int n) {
76 if (n % 2 == 1) {
77 return 0;
78 }
79
80 final int iMax = n / 2;
81 double p = 1;
82 double q = 1;
83 for (int i = 0; i < iMax; i++) {
84 p *= 2 * i + 1;
85 q *= 2;
86 }
87
88 return p / q * SQRT_PI;
89 }
90
91 @ParameterizedTest
92 @MethodSource("getParameters")
93 void testAllMonomials(int numberOfPoints, int maxDegree, double eps,
94 double numUlps) {
95 super.testAllMonomials(factory.hermite(numberOfPoints), maxDegree, eps,
96 numUlps);
97 }
98 }