Added test for consistency of cumulativeProbability(double,double) and cumulativeProbability(double). Contributed by Christian Winter.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1173313 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
112b496420
commit
1019cefed6
|
@ -20,6 +20,7 @@ package org.apache.commons.math.distribution;
|
|||
import org.apache.commons.math.TestUtils;
|
||||
import org.apache.commons.math.util.FastMath;
|
||||
import org.apache.commons.math.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math.exception.NumberIsTooLargeException;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -144,12 +145,30 @@ public abstract class ContinuousDistributionAbstractTest {
|
|||
* using current test instance data
|
||||
*/
|
||||
protected void verifyCumulativeProbabilities() throws Exception {
|
||||
// verify cumulativeProbability(double)
|
||||
for (int i = 0; i < cumulativeTestPoints.length; i++) {
|
||||
TestUtils.assertEquals("Incorrect cumulative probability value returned for "
|
||||
+ cumulativeTestPoints[i], cumulativeTestValues[i],
|
||||
distribution.cumulativeProbability(cumulativeTestPoints[i]),
|
||||
getTolerance());
|
||||
}
|
||||
// verify cumulativeProbability(double, double)
|
||||
for (int i = 0; i < cumulativeTestPoints.length; i++) {
|
||||
for (int j = 0; j < cumulativeTestPoints.length; j++) {
|
||||
if (cumulativeTestPoints[i] <= cumulativeTestPoints[j]) {
|
||||
TestUtils.assertEquals(cumulativeTestValues[j] - cumulativeTestValues[i],
|
||||
distribution.cumulativeProbability(cumulativeTestPoints[i], cumulativeTestPoints[j]),
|
||||
getTolerance());
|
||||
} else {
|
||||
try {
|
||||
distribution.cumulativeProbability(cumulativeTestPoints[i], cumulativeTestPoints[j]);
|
||||
} catch (NumberIsTooLargeException e) {
|
||||
continue;
|
||||
}
|
||||
Assert.fail("distribution.cumulativeProbability(double, double) should have thrown an exception that second argument is too large");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue