KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2005 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
17 package org.apache.commons.math.distribution;
18
19 /**
20  * Test cases for WeibullDistribution.
21  * Extends ContinuousDistributionAbstractTest. See class javadoc for
22  * ContinuousDistributionAbstractTest for details.
23  *
24  * @version $Revision: 1.8 $ $Date: 2004-07-24 16:41:37 -0500 (Sat, 24 Jul 2004) $
25  */

26 public class WeibullDistributionTest extends ContinuousDistributionAbstractTest {
27     
28     /**
29      * Constructor for CauchyDistributionTest.
30      * @param arg0
31      */

32     public WeibullDistributionTest(String JavaDoc arg0) {
33         super(arg0);
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().createWeibullDistribution(1.2, 2.1);
41     }
42     
43     /** Creates the default cumulative probability distribution test input values */
44     public double[] makeCumulativeTestPoints() {
45         // quantiles computed using Mathematica
46
return new double[] {0.00664355181d, 0.04543282833d, 0.09811627374d,
47                 0.1767135246d, 0.3219468654d, 4.207902826d, 5.23968437d,
48                 6.232056007d, 7.497630467d, 10.51154969d};
49     }
50     
51     /** Creates the default cumulative probability density test expected values */
52     public double[] makeCumulativeTestValues() {
53         return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.900d, 0.950d,
54                 0.975d, 0.990d, 0.999d};
55     }
56     
57     //---------------------------- Additional test cases -------------------------
58

59     public void testInverseCumulativeProbabilityExtremes() throws Exception JavaDoc {
60         setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
61         setInverseCumulativeTestValues(
62                 new double[] {0.0, Double.POSITIVE_INFINITY});
63         verifyInverseCumulativeProbabilities();
64     }
65     
66     public void testAlpha() {
67         WeibullDistribution distribution = (WeibullDistribution) getDistribution();
68         double expected = Math.random();
69         distribution.setShape(expected);
70         assertEquals(expected, distribution.getShape(), 0.0);
71     }
72     
73     public void testBeta() {
74         WeibullDistribution distribution = (WeibullDistribution) getDistribution();
75         double expected = Math.random();
76         distribution.setScale(expected);
77         assertEquals(expected, distribution.getScale(), 0.0);
78     }
79     
80     public void testSetAlpha() {
81         WeibullDistribution distribution = (WeibullDistribution) getDistribution();
82         try {
83             distribution.setShape(0.0);
84             fail("Can not have 0.0 alpha.");
85         } catch (IllegalArgumentException JavaDoc ex) {
86             // success
87
}
88         
89         try {
90             distribution.setShape(-1.0);
91             fail("Can not have negative alpha.");
92         } catch (IllegalArgumentException JavaDoc ex) {
93             // success
94
}
95     }
96     
97     public void testSetBeta() {
98         WeibullDistribution distribution = (WeibullDistribution) getDistribution();
99         try {
100             distribution.setScale(0.0);
101             fail("Can not have 0.0 beta.");
102         } catch (IllegalArgumentException JavaDoc ex) {
103             // success
104
}
105         
106         try {
107             distribution.setScale(-1.0);
108             fail("Can not have negative beta.");
109         } catch (IllegalArgumentException JavaDoc ex) {
110             // success
111
}
112     }
113 }
114
Popular Tags