org.apache.commons.math.distribution
Class ContinuousDistributionAbstractTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.commons.math.distribution.ContinuousDistributionAbstractTest
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
CauchyDistributionTest, ChiSquareDistributionTest, ExponentialDistributionTest, FDistributionTest, GammaDistributionTest, NormalDistributionTest, TDistributionTest, WeibullDistributionTest

public abstract class ContinuousDistributionAbstractTest
extends junit.framework.TestCase

Abstract base class for ContinuousDistribution tests.

To create a concrete test class for a continuous distribution implementation, first implement makeDistribution() to return a distribution instance to use in tests. Then implement each of the test data generation methods below. In each case, the test points and test values arrays returned represent parallel arrays of inputs and expected values for the distribution returned by makeDistribution(). Default implementations are provided for the makeInverseXxx methods that just invert the mapping defined by the arrays returned by the makeCumulativeXxx methods.

makeCumulativeTestPoints() -- arguments used to test cumulative probabilities makeCumulativeTestValues() -- expected cumulative probabilites makeInverseCumulativeTestPoints() -- arguments used to test inverse cdf makeInverseCumulativeTestValues() -- expected inverse cdf values

To implement additional test cases with different distribution instances and test data, use the setXxx methods for the instance data in test cases and call the verifyXxx methods to verify results.

Error tolerance can be overriden by implementing getTolerance().

Test data should be validated against reference tables or other packages where possible, and the source of the reference data and/or validation should be documented in the test cases. A framework for validating distribution data against R is included in the /src/test/R source tree.

See NormalDistributionTest and ChiSquareDistributionTest for examples.

Version:
$Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $

Constructor Summary
ContinuousDistributionAbstractTest(String name)
          Constructor for ContinuousDistributionAbstractTest.
 
Method Summary
protected  double[] getCumulativeTestPoints()
           
protected  double[] getCumulativeTestValues()
           
protected  org.apache.commons.math.distribution.ContinuousDistribution getDistribution()
           
protected  double[] getInverseCumulativeTestPoints()
           
protected  double[] getInverseCumulativeTestValues()
           
protected  double getTolerance()
           
abstract  double[] makeCumulativeTestPoints()
          Creates the default cumulative probability density test input values
abstract  double[] makeCumulativeTestValues()
          Creates the default cumulative probability density test expected values
abstract  org.apache.commons.math.distribution.ContinuousDistribution makeDistribution()
          Creates the default continuous distribution instance to use in tests.
 double[] makeInverseCumulativeTestPoints()
          Creates the default inverse cumulative probability test input values
 double[] makeInverseCumulativeTestValues()
          Creates the default inverse cumulative probability density test expected values
protected  void setCumulativeTestPoints(double[] cumulativeTestPoints)
           
protected  void setCumulativeTestValues(double[] cumulativeTestValues)
           
protected  void setDistribution(org.apache.commons.math.distribution.ContinuousDistribution distribution)
           
protected  void setInverseCumulativeTestPoints(double[] inverseCumulativeTestPoints)
           
protected  void setInverseCumulativeTestValues(double[] inverseCumulativeTestValues)
           
protected  void setTolerance(double tolerance)
           
protected  void setUp()
          Setup sets all test instance data to default values
protected  void tearDown()
          Cleans up test instance data
 void testConsistency()
          Verifies that probability computations are consistent
 void testCumulativeProbabilities()
          Verifies that cumulative probability density calculations match expected values using default test instance data
 void testIllegalArguments()
          Verifies that illegal arguments are correctly handled
 void testInverseCumulativeProbabilities()
          Verifies that inverse cumulative probability density calculations match expected values using default test instance data
protected  void verifyCumulativeProbabilities()
          Verifies that cumulative probability density calculations match expected values using current test instance data
protected  void verifyInverseCumulativeProbabilities()
          Verifies that inverse cumulative probability density calculations match expected values using current test instance data
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ContinuousDistributionAbstractTest

public ContinuousDistributionAbstractTest(String name)
Constructor for ContinuousDistributionAbstractTest.

Parameters:
name -
Method Detail

makeDistribution

public abstract org.apache.commons.math.distribution.ContinuousDistribution makeDistribution()
Creates the default continuous distribution instance to use in tests.


makeCumulativeTestPoints

public abstract double[] makeCumulativeTestPoints()
Creates the default cumulative probability density test input values


makeCumulativeTestValues

public abstract double[] makeCumulativeTestValues()
Creates the default cumulative probability density test expected values


makeInverseCumulativeTestPoints

public double[] makeInverseCumulativeTestPoints()
Creates the default inverse cumulative probability test input values


makeInverseCumulativeTestValues

public double[] makeInverseCumulativeTestValues()
Creates the default inverse cumulative probability density test expected values


setUp

protected void setUp()
              throws Exception
Setup sets all test instance data to default values

Overrides:
setUp in class junit.framework.TestCase
Throws:
Exception

tearDown

protected void tearDown()
                 throws Exception
Cleans up test instance data

Overrides:
tearDown in class junit.framework.TestCase
Throws:
Exception

verifyCumulativeProbabilities

protected void verifyCumulativeProbabilities()
                                      throws Exception
Verifies that cumulative probability density calculations match expected values using current test instance data

Throws:
Exception

verifyInverseCumulativeProbabilities

protected void verifyInverseCumulativeProbabilities()
                                             throws Exception
Verifies that inverse cumulative probability density calculations match expected values using current test instance data

Throws:
Exception

testCumulativeProbabilities

public void testCumulativeProbabilities()
                                 throws Exception
Verifies that cumulative probability density calculations match expected values using default test instance data

Throws:
Exception

testInverseCumulativeProbabilities

public void testInverseCumulativeProbabilities()
                                        throws Exception
Verifies that inverse cumulative probability density calculations match expected values using default test instance data

Throws:
Exception

testConsistency

public void testConsistency()
                     throws Exception
Verifies that probability computations are consistent

Throws:
Exception

testIllegalArguments

public void testIllegalArguments()
                          throws Exception
Verifies that illegal arguments are correctly handled

Throws:
Exception

getCumulativeTestPoints

protected double[] getCumulativeTestPoints()
Returns:
Returns the cumulativeTestPoints.

setCumulativeTestPoints

protected void setCumulativeTestPoints(double[] cumulativeTestPoints)
Parameters:
cumulativeTestPoints - The cumulativeTestPoints to set.

getCumulativeTestValues

protected double[] getCumulativeTestValues()
Returns:
Returns the cumulativeTestValues.

setCumulativeTestValues

protected void setCumulativeTestValues(double[] cumulativeTestValues)
Parameters:
cumulativeTestValues - The cumulativeTestValues to set.

getDistribution

protected org.apache.commons.math.distribution.ContinuousDistribution getDistribution()
Returns:
Returns the distribution.

setDistribution

protected void setDistribution(org.apache.commons.math.distribution.ContinuousDistribution distribution)
Parameters:
distribution - The distribution to set.

getInverseCumulativeTestPoints

protected double[] getInverseCumulativeTestPoints()
Returns:
Returns the inverseCumulativeTestPoints.

setInverseCumulativeTestPoints

protected void setInverseCumulativeTestPoints(double[] inverseCumulativeTestPoints)
Parameters:
inverseCumulativeTestPoints - The inverseCumulativeTestPoints to set.

getInverseCumulativeTestValues

protected double[] getInverseCumulativeTestValues()
Returns:
Returns the inverseCumulativeTestValues.

setInverseCumulativeTestValues

protected void setInverseCumulativeTestValues(double[] inverseCumulativeTestValues)
Parameters:
inverseCumulativeTestValues - The inverseCumulativeTestValues to set.

getTolerance

protected double getTolerance()
Returns:
Returns the tolerance.

setTolerance

protected void setTolerance(double tolerance)
Parameters:
tolerance - The tolerance to set.


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.