01: /*
02: * Copyright 2003-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
24: */
25: public class ExponentialDistributionTest extends
26: ContinuousDistributionAbstractTest {
27:
28: /**
29: * Constructor for ExponentialDistributionTest.
30: * @param name
31: */
32: public ExponentialDistributionTest(String name) {
33: super (name);
34: }
35:
36: //-------------- Implementations for abstract methods -----------------------
37:
38: /** Creates the default continuous distribution instance to use in tests. */
39: public ContinuousDistribution makeDistribution() {
40: return DistributionFactory.newInstance()
41: .createExponentialDistribution(5.0);
42: }
43:
44: /** Creates the default cumulative probability distribution test input values */
45: public double[] makeCumulativeTestPoints() {
46: // quantiles computed using R version 1.8.1 (linux version)
47: return new double[] { 0.005002502d, 0.05025168d, 0.1265890d,
48: 0.2564665d, 0.5268026d, 34.53878d, 23.02585d,
49: 18.44440d, 14.97866d, 11.51293d };
50: }
51:
52: /** Creates the default cumulative probability density test expected values */
53: public double[] makeCumulativeTestValues() {
54: return new double[] { 0.001d, 0.01d, 0.025d, 0.05d, 0.1d,
55: 0.999d, 0.990d, 0.975d, 0.950d, 0.900d };
56: }
57:
58: //------------ Additional tests -------------------------------------------
59:
60: public void testCumulativeProbabilityExtremes() throws Exception {
61: setCumulativeTestPoints(new double[] { -2, 0 });
62: setCumulativeTestValues(new double[] { 0, 0 });
63: verifyCumulativeProbabilities();
64: }
65:
66: public void testInverseCumulativeProbabilityExtremes()
67: throws Exception {
68: setInverseCumulativeTestPoints(new double[] { 0, 1 });
69: setInverseCumulativeTestValues(new double[] { 0,
70: Double.POSITIVE_INFINITY });
71: verifyInverseCumulativeProbabilities();
72: }
73:
74: public void testCumulativeProbability2() throws Exception {
75: double actual = getDistribution().cumulativeProbability(0.25,
76: 0.75);
77: assertEquals(0.0905214, actual, 10e-4);
78: }
79:
80: public void testMeanAccessors() {
81: ExponentialDistribution distribution = (ExponentialDistribution) getDistribution();
82: assertEquals(5d, distribution.getMean(), Double.MIN_VALUE);
83: distribution.setMean(2d);
84: assertEquals(2d, distribution.getMean(), Double.MIN_VALUE);
85: try {
86: distribution.setMean(0);
87: fail("Expecting IllegalArgumentException for 0 mean");
88: } catch (IllegalArgumentException ex) {
89: // expected
90: }
91: }
92:
93: }
|