commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1344943 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java
Date Thu, 31 May 2012 23:55:13 GMT
Author: tn
Date: Thu May 31 23:55:12 2012
New Revision: 1344943

URL: http://svn.apache.org/viewvc?rev=1344943&view=rev
Log:
[MATH-644] added unit test.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java?rev=1344943&r1=1344942&r2=1344943&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java
Thu May 31 23:55:12 2012
@@ -21,6 +21,7 @@ import org.apache.commons.math3.TestUtil
 import org.apache.commons.math3.exception.NotPositiveException;
 import org.apache.commons.math3.exception.NotStrictlyPositiveException;
 import org.apache.commons.math3.exception.NumberIsTooLargeException;
+import org.apache.commons.math3.util.Precision;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -266,4 +267,21 @@ public class HypergeometricDistributionT
         Assert.assertEquals(dist.getNumericalMean(), 55d * 200d / 3000d, tol);
         Assert.assertEquals(dist.getNumericalVariance(), ( 200d * 55d * (3000d - 200d) *
(3000d - 55d) ) / ( (3000d * 3000d * 2999d) ), tol);
     }
+    
+    @Test
+    public void testMath644() {
+        int N = 14761461;  // population
+        int m = 1035;      // successes in population
+        int n = 1841;      // number of trials
+
+        int k = 0;
+        final HypergeometricDistribution dist = new HypergeometricDistribution(N, m, n);
+        
+        Assert.assertTrue(Precision.compareTo(1.0, dist.upperCumulativeProbability(k), 1)
== 0);
+        Assert.assertTrue(Precision.compareTo(dist.cumulativeProbability(k), 0.0, 1) >
0);
+        
+        // another way to calculate the upper cumulative probability
+        double upper = 1.0 - dist.cumulativeProbability(k) + dist.probability(k);
+        Assert.assertTrue(Precision.compareTo(1.0, upper, 1) == 0);
+    }
 }



Mime
View raw message