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 * http://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 package org.apache.commons.math4.legacy.analysis.integration.gauss;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21
22 import org.junit.runner.RunWith;
23 import org.junit.runners.Parameterized;
24 import org.junit.runners.Parameterized.Parameters;
25
26 /**
27 * Test of the {@link LegendreHighPrecisionRuleFactory}.
28 * This parameterized test extends the standard test for Gaussian quadrature
29 * rule, where each monomial is tested in turn.
30 * Parametrization allows to test automatically 0, 1, ... , {@link #MAX_NUM_POINTS}
31 * quadrature rules.
32 *
33 */
34 @RunWith(value=Parameterized.class)
35 public class LegendreHighPrecisionParametricTest extends GaussianQuadratureAbstractTest {
36 private static GaussIntegratorFactory factory = new GaussIntegratorFactory();
37
38 /**
39 * The highest order quadrature rule to be tested.
40 */
41 public static final int MAX_NUM_POINTS = 30;
42
43 /**
44 * Creates a new instance of this test, with the specified number of nodes
45 * for the Gauss-Legendre quadrature rule.
46 *
47 * @param numberOfPoints Order of integration rule.
48 * @param maxDegree Maximum degree of monomials to be tested.
49 * @param eps Value of ε.
50 * @param numUlps Value of the maximum relative error (in ulps).
51 */
52 public LegendreHighPrecisionParametricTest(int numberOfPoints,
53 int maxDegree,
54 double eps,
55 double numUlps) {
56 super(factory.legendreHighPrecision(numberOfPoints),
57 maxDegree, eps, numUlps);
58 }
59
60 /**
61 * Returns the collection of parameters to be passed to the constructor of
62 * this class.
63 * Gauss-Legendre quadrature rules of order 1, ..., {@link #MAX_NUM_POINTS}
64 * will be constructed.
65 *
66 * @return the collection of parameters for this parameterized test.
67 */
68 @SuppressWarnings("boxing") // OK here
69 @Parameters
70 public static Collection<Object[]> getParameters() {
71 final ArrayList<Object[]> parameters = new ArrayList<>();
72 for (int k = 1; k <= MAX_NUM_POINTS; k++) {
73 parameters.add(new Object[] { k, 2 * k - 1, Math.ulp(1d), 13d });
74 }
75 return parameters;
76 }
77
78 @Override
79 public double getExpectedValue(final int n) {
80 if ((n & 1) == 1) {
81 // n is odd
82 return 0;
83 }
84 return 2d / (n + 1);
85 }
86 }