From c4f81a87ee8fe307bc391ba04caac04e4c51f06b Mon Sep 17 00:00:00 2001 From: Sebastien Brisard Date: Fri, 31 Aug 2012 02:01:11 +0000 Subject: [PATCH] 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 --- .../commons/math3/special/GammaTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/test/java/org/apache/commons/math3/special/GammaTest.java b/src/test/java/org/apache/commons/math3/special/GammaTest.java index 5e9ab415f..c52f96603 100644 --- a/src/test/java/org/apache/commons/math3/special/GammaTest.java +++ b/src/test/java/org/apache/commons/math3/special/GammaTest.java @@ -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)); }