commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1379255 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java
Date Fri, 31 Aug 2012 02:01:11 GMT
Author: celestin
Date: Fri Aug 31 02:01:11 2012
New Revision: 1379255

URL: http://svn.apache.org/viewvc?rev=1379255&view=rev
Log:
MATH-849: unit tests for double Gamma.logGamma1p(double).

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java?rev=1379255&r1=1379254&r2=1379255&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/special/GammaTest.java
Fri Aug 31 02:01:11 2012
@@ -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));
     }



Mime
View raw message