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 TDistributionTest.java
Date Sun, 30 May 2004 22:13:35 GMT
psteitz     2004/05/30 15:13:35

  Modified:    math/src/test/org/apache/commons/math/distribution
                        TDistributionTest.java
  Log:
  Modified to extend ContinuousDistributionAbstract test, improved coverage.
  
  Revision  Changes    Path
  1.14      +58 -122   jakarta-commons/math/src/test/org/apache/commons/math/distribution/TDistributionTest.java
  
  Index: TDistributionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/TDistributionTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TDistributionTest.java	28 Feb 2004 21:58:33 -0000	1.13
  +++ TDistributionTest.java	30 May 2004 22:13:35 -0000	1.14
  @@ -15,149 +15,85 @@
    */
   package org.apache.commons.math.distribution;
   
  -import org.apache.commons.math.MathException;
  -
  -import junit.framework.TestCase;
  -
   /**
  + * Test cases for TDistribution.
  + * Extends ContinuousDistributionAbstractTest.  See class javadoc for
  + * ContinuousDistributionAbstractTest for details.
  + * 
    * @version $Revision$ $Date$
    */
  -public class TDistributionTest extends TestCase {
  -    private TDistribution t;
  +public class TDistributionTest extends ContinuousDistributionAbstractTest {
   
       /**
  -     * Constructor for ChiSquareDistributionTest.
  +     * Constructor for TDistributionTest.
        * @param name
        */
       public TDistributionTest(String name) {
           super(name);
       }
   
  -    /*
  -     * @see TestCase#setUp()
  -     */
  -    protected void setUp() throws Exception {
  -        super.setUp();
  -        t = DistributionFactory.newInstance().createTDistribution(5.0);
  -    }
  -
  -    /*
  -     * @see TestCase#tearDown()
  -     */
  -    protected void tearDown() throws Exception {
  -        t = null;
  -        super.tearDown();
  -    }
  -
  -    public void testInverseCumulativeProbability001() {
  -        testValue(-5.893, .001);
  -    }
  -
  -    public void testInverseCumulativeProbability010() {
  -        testValue(-3.365, .010);
  -    }
  -
  -    public void testInverseCumulativeProbability025() {
  -        testValue(-2.571, .025);
  -    }
  -
  -    public void testInverseCumulativeProbability050() {
  -        testValue(-2.015, .050);
  -    }
  -
  -    public void testInverseCumulativeProbability100() {
  -        testValue(-1.476, .100);
  -    }
  -
  -    public void testInverseCumulativeProbability999() {
  -        testValue(5.893, .999);
  -    }
  -
  -    public void testInverseCumulativeProbability990() {
  -        testValue(3.365, .990);
  -    }
  -
  -    public void testInverseCumulativeProbability975() {
  -        testValue(2.571, .975);
  -    }
  -
  -    public void testInverseCumulativeProbability950() {
  -        testValue(2.015, .950);
  -    }
  -
  -    public void testInverseCumulativeProbability900() {
  -        testValue(1.476, .900);
  -    }
  -
  -    public void testCumulativeProbability001() {
  -        testProbability(-5.893, .001);
  -    }
  -
  -    public void testCumulativeProbability010() {
  -        testProbability(-3.365, .010);
  -    }
  -
  -    public void testCumulativeProbability025() {
  -        testProbability(-2.571, .025);
  -    }
  -
  -    public void testCumulativeProbability050() {
  -        testProbability(-2.015, .050);
  -    }
  -
  -    public void testCumulativeProbability100() {
  -        testProbability(-1.476, .100);
  -    }
  -
  -    public void testCumulativeProbability999() {
  -        testProbability(5.893, .999);
  -    }
  -
  -    public void testCumulativeProbability990() {
  -        testProbability(3.365, .990);
  -    }
  -
  -    public void testCumulativeProbability975() {
  -        testProbability(2.571, .975);
  +//-------------- Implementations for abstract methods -----------------------
  +    
  +    /** Creates the default continuous distribution instance to use in tests. */
  +    public ContinuousDistribution makeDistribution() {
  +        return DistributionFactory.newInstance().createTDistribution(5.0);
  +    }   
  +    
  +    /** 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[] {-5.89343,-3.36493, -2.570582, -2.015048,
  +            -1.475884, 5.89343, 3.36493, 2.570582,
  +            2.015048, 1.475884};
       }
  -
  -    public void testCumulativeProbability950() {
  -        testProbability(2.015, .950);
  +    
  +    /** 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}; 
       }
  -
  -    public void testCumulativeProbability900() {
  -        testProbability(1.476, .900);
  +    
  +    // --------------------- Override tolerance  --------------
  +    protected void setup() throws Exception {
  +        super.setUp();
  +        setTolerance(1E-6);
       }
   
  +    //---------------------------- Additional test cases -------------------------
       /**
        * @see <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27243">
        *      Bug report that prompted this unit test.</a>
        */
  -    public void testCumulativeProbabilityAgaintStackOverflow() {
  -    	try {
  -	    	TDistributionImpl td = new TDistributionImpl(5.);
  -	    	double est;
  -	    	est = td.cumulativeProbability(.1);
  -	    	est = td.cumulativeProbability(.01);
  -    	} catch(MathException ex) {
  -    		fail(ex.getMessage());
  -    	}
  +    public void testCumulativeProbabilityAgaintStackOverflow() throws Exception {
  +    	TDistributionImpl td = new TDistributionImpl(5.);
  +    	double est;
  +    	est = td.cumulativeProbability(.1);
  +    	est = td.cumulativeProbability(.01);
       }
       
  -    private void testProbability(double x, double expected) {
  -        try {
  -            double actual = t.cumulativeProbability(x);
  -            assertEquals(expected, actual, 10e-4);
  -        } catch (MathException e) {
  -        	fail(e.getMessage());
  -        }
  +    public void testSmallDf() throws Exception {
  +        setDistribution(DistributionFactory.newInstance().createTDistribution(1d));
  +        setTolerance(1E-4);
  +        // quantiles computed using R version 1.8.1 (linux version)
  +        setCumulativeTestPoints(new double[] {-318.3088, -31.82052, -12.70620, -6.313752,
  +            -3.077684, 318.3088, 31.82052, 12.70620,
  +            6.313752, 3.077684});
  +        setInverseCumulativeTestValues(getCumulativeTestPoints());
  +        verifyCumulativeProbabilities();
  +        verifyInverseCumulativeProbabilities();
       }
  -    private void testValue(double expected, double p) {
  +    
  +    public void testDfAccessors() {
  +        TDistribution distribution = (TDistribution) getDistribution();
  +        assertEquals(5d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE);
  +        distribution.setDegreesOfFreedom(4d);
  +        assertEquals(4d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE);
           try {
  -            double actual = t.inverseCumulativeProbability(p);
  -            assertEquals(expected, actual, 10e-4);
  -        } catch (MathException e) {
  -        	fail(e.getMessage());
  +            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