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