KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > math > distribution > ExponentialDistributionTest


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.math.distribution;
17
18 /**
19  * Test cases for ExponentialDistribution.
20  * Extends ContinuousDistributionAbstractTest. See class javadoc for
21  * ContinuousDistributionAbstractTest for details.
22  *
23  * @version $Revision$ $Date: 2005-02-26 05:11:52 -0800 (Sat, 26 Feb 2005) $
24  */

25 public class ExponentialDistributionTest extends ContinuousDistributionAbstractTest {
26
27     /**
28      * Constructor for ExponentialDistributionTest.
29      * @param name
30      */

31     public ExponentialDistributionTest(String JavaDoc name) {
32         super(name);
33     }
34
35     //-------------- Implementations for abstract methods -----------------------
36

37     /** Creates the default continuous distribution instance to use in tests. */
38     public ContinuousDistribution makeDistribution() {
39         return DistributionFactory.newInstance().createExponentialDistribution(5.0);
40     }
41     
42     /** Creates the default cumulative probability distribution test input values */
43     public double[] makeCumulativeTestPoints() {
44         // quantiles computed using R version 1.8.1 (linux version)
45
return new double[] {0.005002502d, 0.05025168d, 0.1265890d, 0.2564665d, 0.5268026d,
46                 34.53878d, 23.02585d, 18.44440d, 14.97866d, 11.51293d};
47     }
48     
49     /** Creates the default cumulative probability density test expected values */
50     public double[] makeCumulativeTestValues() {
51         return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d,
52                 0.990d, 0.975d, 0.950d, 0.900d};
53     }
54     
55     //------------ Additional tests -------------------------------------------
56

57     public void testCumulativeProbabilityExtremes() throws Exception JavaDoc {
58         setCumulativeTestPoints(new double[] {-2, 0});
59         setCumulativeTestValues(new double[] {0, 0});
60         verifyCumulativeProbabilities();
61     }
62
63     public void testInverseCumulativeProbabilityExtremes() throws Exception JavaDoc {
64          setInverseCumulativeTestPoints(new double[] {0, 1});
65          setInverseCumulativeTestValues(new double[] {0, Double.POSITIVE_INFINITY});
66          verifyInverseCumulativeProbabilities();
67     }
68
69     public void testCumulativeProbability2() throws Exception JavaDoc {
70         double actual = getDistribution().cumulativeProbability(0.25, 0.75);
71         assertEquals(0.0905214, actual, 10e-4);
72     }
73     
74     public void testMeanAccessors() {
75         ExponentialDistribution distribution = (ExponentialDistribution) getDistribution();
76         assertEquals(5d, distribution.getMean(), Double.MIN_VALUE);
77         distribution.setMean(2d);
78         assertEquals(2d, distribution.getMean(), Double.MIN_VALUE);
79         try {
80             distribution.setMean(0);
81             fail("Expecting IllegalArgumentException for 0 mean");
82         } catch (IllegalArgumentException JavaDoc ex) {
83             // expected
84
}
85     }
86    
87 }
88
Popular Tags