Modified to extent ContinuousDistributionAbstractTest.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141253 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2004-05-31 00:55:22 +00:00
parent 5b9f353eea
commit 09d2c9d132
1 changed files with 65 additions and 4 deletions

View File

@ -16,12 +16,73 @@
package org.apache.commons.math.distribution;
import junit.framework.TestCase;
/**
* @version $Revision: 1.16 $ $Date: 2004/05/23 21:34:19 $
* Test cases for GammaDistribution.
* Extends ContinuousDistributionAbstractTest. See class javadoc for
* ContinuousDistributionAbstractTest for details.
*
* @version $Revision: 1.17 $ $Date: 2004/05/31 00:55:22 $
*/
public class GammaDistributionTest extends TestCase {
public class GammaDistributionTest extends ContinuousDistributionAbstractTest {
/**
* Constructor for GammaDistributionTest.
* @param name
*/
public GammaDistributionTest(String name) {
super(name);
}
//-------------- Implementations for abstract methods -----------------------
/** Creates the default continuous distribution instance to use in tests. */
public ContinuousDistribution makeDistribution() {
return DistributionFactory.newInstance().createGammaDistribution(4d, 2d);
}
/** Creates the default cumulative probability distribution test input values */
public double[] makeCumulativeTestPoints() {
// quantiles computed using R version 1.8.1 (linux version)
return new double[] {0.8571048, 1.646497, 2.179731, 2.732637,
3.489539, 26.12448, 20.09024, 17.53455,
15.50731, 13.36157};
}
/** Creates the default cumulative probability density test expected values */
public double[] makeCumulativeTestValues() {
return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d,
0.990d, 0.975d, 0.950d, 0.900d};
}
// --------------------- Override tolerance --------------
protected void setup() throws Exception {
super.setUp();
setTolerance(1E-6);
}
//---------------------------- Additional test cases -------------------------
public void testParameterAccessors() {
GammaDistribution distribution = (GammaDistribution) getDistribution();
assertEquals(4d, distribution.getAlpha(), 0);
distribution.setAlpha(3d);
assertEquals(3d, distribution.getAlpha(), 0);
assertEquals(2d, distribution.getBeta(), 0);
distribution.setBeta(4d);
assertEquals(4d, distribution.getBeta(), 0);
try {
distribution.setAlpha(0d);
fail("Expecting IllegalArgumentException for alpha = 0");
} catch (IllegalArgumentException ex) {
// expected
}
try {
distribution.setBeta(0d);
fail("Expecting IllegalArgumentException for beta = 0");
} catch (IllegalArgumentException ex) {
// expected
}
}
public void testProbabilities() throws Exception {
testProbability(-1.000, 4.0, 2.0, .0000);
testProbability(15.501, 4.0, 2.0, .9499);