MATH-849: unit tests for double Gamma.logGamma1p(double).

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1379255 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2012-08-31 02:01:11 +00:00
parent 1398a16c7c
commit c4f81a87ee
1 changed files with 46 additions and 0 deletions

View File

@ -389,6 +389,52 @@ public class GammaTest {
Gamma.invGamma1pm1(1.51);
}
private static final double[][] LOG_GAMMA1P_REF = {
{ - 0.5 , .5723649429247001 },
{ - 0.375 , .3608294954889402 },
{ - 0.25 , .2032809514312954 },
{ - 0.125 , .08585870722533433 },
{ 0.0 , 0.0 },
{ 0.125 , - .06002318412603958 },
{ 0.25 , - .09827183642181316 },
{ 0.375 , - .1177552707410788 },
{ 0.5 , - .1207822376352452 },
{ 0.625 , - .1091741337567954 },
{ 0.75 , - .08440112102048555 },
{ 0.875 , - 0.0476726853991883 },
{ 1.0 , 0.0 },
{ 1.125 , .05775985153034387 },
{ 1.25 , .1248717148923966 },
{ 1.375 , .2006984603774558 },
{ 1.5 , .2846828704729192 },
};
@Test
public void testLogGamma1p() {
final int ulps = 3;
for (int i = 0; i < LOG_GAMMA1P_REF.length; i++) {
final double[] ref = LOG_GAMMA1P_REF[i];
final double x = ref[0];
final double expected = ref[1];
final double actual = Gamma.logGamma1p(x);
final double tol = ulps * FastMath.ulp(expected);
Assert.assertEquals(Double.toString(x), expected, actual, tol);
}
}
@Test(expected = NumberIsTooSmallException.class)
public void testLogGamma1pPrecondition1() {
Gamma.logGamma1p(-0.51);
}
@Test(expected = NumberIsTooLargeException.class)
public void testLogGamma1pPrecondition2() {
Gamma.logGamma1p(1.51);
}
private void checkRelativeError(String msg, double expected, double actual, double tolerance) {
Assert.assertEquals(msg, expected, actual, FastMath.abs(tolerance * actual));
}