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.hipparchus.util.Binary64; 28 import org.hipparchus.util.Binary64Field; 29 import org.junit.runner.RunWith; 30 import org.junit.runners.Parameterized; 31 import org.junit.runners.Parameterized.Parameters; 32 33 /** 34 * Test of the {@link FieldLegendreRuleFactory}. 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 @RunWith(value=Parameterized.class) 42 public class FieldLegendreParametricTest extends FieldGaussianQuadratureAbstractTest { 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 * Creates a new instance of this test, with the specified number of nodes 52 * for the Gauss-Legendre quadrature rule. 53 * 54 * @param numberOfPoints Order of integration rule. 55 * @param maxDegree Maximum degree of monomials to be tested. 56 * @param eps Value of ε. 57 * @param numUlps Value of the maximum relative error (in ulps). 58 */ 59 public FieldLegendreParametricTest(int numberOfPoints, 60 int maxDegree, 61 double eps, 62 double numUlps) { 63 super(factory.legendre(numberOfPoints), 64 maxDegree, eps, numUlps); 65 } 66 67 /** 68 * Returns the collection of parameters to be passed to the constructor of 69 * this class. 70 * Gauss-Legendre quadrature rules of order 1, ..., {@link #MAX_NUM_POINTS} 71 * will be constructed. 72 * 73 * @return the collection of parameters for this parameterized test. 74 */ 75 @Parameters 76 public static Collection<Object[]> getParameters() { 77 final ArrayList<Object[]> parameters = new ArrayList<Object[]>(); 78 for (int k = 1; k <= MAX_NUM_POINTS; k++) { 79 parameters.add(new Object[] { k, 2 * k - 1, Math.ulp(1d), 91d }); 80 } 81 return parameters; 82 } 83 84 @Override 85 public double getExpectedValue(final int n) { 86 if (n % 2 == 1) { 87 return 0; 88 } 89 return 2d / (n + 1); 90 } 91 }