commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/distribution ChiSquareDistributionTest.java
Date Sat, 29 May 2004 22:52:44 GMT
psteitz     2004/05/29 15:52:44

  Modified:    math/src/test/org/apache/commons/math/distribution
                        ChiSquareDistributionTest.java
  Log:
  Modified to extend ContinuousDistributionAbstractTest, improved coverage.
  
  Revision  Changes    Path
  1.15      +59 -62    jakarta-commons/math/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java
  
  Index: ChiSquareDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ChiSquareDistributionTest.java	23 May 2004 21:34:19 -0000	1.14
  +++ ChiSquareDistributionTest.java	29 May 2004 22:52:44 -0000	1.15
  @@ -16,77 +16,74 @@
   
   package org.apache.commons.math.distribution;
   
  -import junit.framework.TestCase;
  -
   /**
  + * Test cases for ChiSquareDistribution.
  + * Extends ContinuousDistributionAbstractTest.  See class javadoc for
  + * ContinuousDistributionAbstractTest for details.
  + * 
    * @version $Revision$ $Date$
    */
  -public class ChiSquareDistributionTest extends TestCase {
  -    private ChiSquaredDistribution chiSquare;
  +public class ChiSquareDistributionTest extends ContinuousDistributionAbstractTest {
       
  -	/**
  -	 * Constructor for ChiSquareDistributionTest.
  -	 * @param name
  -	 */
  -	public ChiSquareDistributionTest(String name) {
  -		super(name);
  -	}
  -
  -	/*
  -	 * @see TestCase#setUp()
  -	 */
  -	protected void setUp() throws Exception {
  -		super.setUp();
  -        chiSquare = DistributionFactory.newInstance().createChiSquareDistribution(5.0);
  -	}
  -
  -	/*
  -	 * @see TestCase#tearDown()
  -	 */
  -	protected void tearDown() throws Exception {
  -        chiSquare = null;
  -		super.tearDown();
  -	}
  -
  -    public void testLowerTailProbability() throws Exception {
  -        testProbability( .210, .001);
  -        testProbability( .554, .010);
  -        testProbability( .831, .025);
  -        testProbability(1.145, .050);
  -        testProbability(1.610, .100);
  -    }
  -
  -    public void testUpperTailProbability() throws Exception {
  -        testProbability(20.515, .999);
  -        testProbability(15.086, .990);
  -        testProbability(12.833, .975);
  -        testProbability(11.070, .950);
  -        testProbability( 9.236, .900);
  +    /**
  +     * Constructor for ChiSquareDistributionTest.
  +     * @param name
  +     */
  +    public ChiSquareDistributionTest(String name) {
  +        super(name);
       }
       
  -    public void testLowerTailValues() throws Exception {
  -        testValue(.001,  .210);
  -        testValue(.010,  .554);
  -        testValue(.025,  .831);
  -        testValue(.050, 1.145);
  -        testValue(.100, 1.610);
  -    }
  +    //-------------- Implementations for abstract methods -----------------------
  +    
  +    /** Creates the default continuous distribution instance to use in tests. */
  +    public ContinuousDistribution makeDistribution() {
  +        return DistributionFactory.newInstance().createChiSquareDistribution(5.0);
  +    }   
       
  -    public void testUpperTailValues() throws Exception {
  -        testValue(.999, 20.515);
  -        testValue(.990, 15.086);
  -        testValue(.975, 12.833);
  -        testValue(.950, 11.070);
  -        testValue(.900,  9.236);
  +    /** 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.210216d, 0.5542981d, 0.8312116d, 1.145476d, 1.610308d, 
  +                20.51501d, 15.08627d, 12.83250d, 11.07050d, 9.236357d};
       }
       
  -    private void testProbability(double x, double expected) throws Exception {
  -        double actual = chiSquare.cumulativeProbability(x);
  -        assertEquals("probability for " + x, expected, actual, 10e-4);
  +    /** 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 -------------------------
       
  -    private void testValue(double p, double expected) throws Exception {
  -        double actual = chiSquare.inverseCumulativeProbability(p);
  -        assertEquals("value for " + p, expected, actual, 10e-4);
  +    public void testSmallDf() throws Exception {
  +        setDistribution(DistributionFactory.newInstance().createChiSquareDistribution(0.1d));
  +        setTolerance(1E-4);
  +        // quantiles computed using R version 1.8.1 (linux version)
  +        setCumulativeTestPoints(new double[] {1.168926E-60, 1.168926E-40, 1.063132E-32,

  +                1.144775E-26, 1.168926E-20, 5.472917, 2.175255, 1.13438, 
  +                0.5318646, 0.1526342});
  +        setInverseCumulativeTestValues(getCumulativeTestPoints());
  +        verifyCumulativeProbabilities();
  +        verifyInverseCumulativeProbabilities();
       }
  +    
  +    public void testDfAccessors() {
  +        ChiSquaredDistribution distribution = (ChiSquaredDistribution) getDistribution();
  +        assertEquals(5d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE);
  +        distribution.setDegreesOfFreedom(4d);
  +        assertEquals(4d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE);
  +        try {
  +            distribution.setDegreesOfFreedom(0d);
  +            fail("Expecting IllegalArgumentException for df = 0");
  +        } catch (IllegalArgumentException ex) {
  +            // expected
  +        }
  +    } 
  +    
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message