MATH-849: unit tests for double Gamma.invGamma1pm1(double).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1379253 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8a3dd3725f
commit
99a9552531
|
@ -17,6 +17,8 @@
|
|||
package org.apache.commons.math3.special;
|
||||
|
||||
import org.apache.commons.math3.TestUtils;
|
||||
import org.apache.commons.math3.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -320,6 +322,75 @@ public class GammaTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Reference values for the {@link GammaNSWC#invGamma1pm1(double)} method.
|
||||
* These values were generated with the following <a
|
||||
* href="http://maxima.sourceforge.net/">Maxima</a> script
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* kill(all);
|
||||
*
|
||||
* fpprec : 64;
|
||||
* gam1(x) := 1 / gamma(1 + x) - 1;
|
||||
* x : makelist(bfloat(i / 8), i, -4, 12);
|
||||
*
|
||||
* for i : 1 while i <= length(x) do print("{",
|
||||
* float(x[i]),
|
||||
* ",",
|
||||
* float(gam1(x[i])),
|
||||
* "},");
|
||||
* </pre>
|
||||
*/
|
||||
// @formatter:off
|
||||
private static final double[][] INV_GAMMA1P_M1_REF = {
|
||||
{ -0.5 , -.4358104164522437 },
|
||||
{ -0.375 , -.3029021533379859 },
|
||||
{ -0.25 , -0.183951060901737 },
|
||||
{ -0.125 , -.08227611018520711 },
|
||||
{ 0.0 , 0.0 },
|
||||
{ 0.125 , .06186116458306091 },
|
||||
{ 0.25 , .1032626513208373 },
|
||||
{ 0.375 , .1249687649039041 },
|
||||
{ 0.5 , .1283791670955126 },
|
||||
{ 0.625 , .1153565546592225 },
|
||||
{ 0.75 , 0.0880652521310173 },
|
||||
{ 0.875 , .04882730264547758 },
|
||||
{ 1.0 , 0.0 },
|
||||
{ 1.125 , -.05612340925950141 },
|
||||
{ 1.25 , -.1173898789433302 },
|
||||
{ 1.375 , -.1818408982517061 },
|
||||
{ 1.5 , -0.247747221936325 },
|
||||
};
|
||||
// @formatter:on
|
||||
|
||||
@Test
|
||||
public void testInvGamma1pm1() {
|
||||
|
||||
final int ulps = 3;
|
||||
for (int i = 0; i < INV_GAMMA1P_M1_REF.length; i++) {
|
||||
final double[] ref = INV_GAMMA1P_M1_REF[i];
|
||||
final double x = ref[0];
|
||||
final double expected = ref[1];
|
||||
final double actual = Gamma.invGamma1pm1(x);
|
||||
final double tol = ulps * FastMath.ulp(expected);
|
||||
Assert.assertEquals(Double.toString(x), expected, actual, tol);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = NumberIsTooSmallException.class)
|
||||
public void testInvGamma1pm1Precondition1() {
|
||||
|
||||
Gamma.invGamma1pm1(-0.51);
|
||||
}
|
||||
|
||||
@Test(expected = NumberIsTooLargeException.class)
|
||||
public void testInvGamma1pm1Precondition2() {
|
||||
|
||||
Gamma.invGamma1pm1(1.51);
|
||||
}
|
||||
|
||||
private void checkRelativeError(String msg, double expected, double actual, double tolerance) {
|
||||
Assert.assertEquals(msg, expected, actual, FastMath.abs(tolerance * actual));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue