001: /*
002: * Copyright 2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.commons.math.distribution;
018:
019: /**
020: * Test cases for WeibullDistribution.
021: * Extends ContinuousDistributionAbstractTest. See class javadoc for
022: * ContinuousDistributionAbstractTest for details.
023: *
024: * @version $Revision: 1.8 $ $Date: 2004-07-24 16:41:37 -0500 (Sat, 24 Jul 2004) $
025: */
026: public class WeibullDistributionTest extends
027: ContinuousDistributionAbstractTest {
028:
029: /**
030: * Constructor for CauchyDistributionTest.
031: * @param arg0
032: */
033: public WeibullDistributionTest(String arg0) {
034: super (arg0);
035: }
036:
037: //-------------- Implementations for abstract methods -----------------------
038:
039: /** Creates the default continuous distribution instance to use in tests. */
040: public ContinuousDistribution makeDistribution() {
041: return DistributionFactory.newInstance()
042: .createWeibullDistribution(1.2, 2.1);
043: }
044:
045: /** Creates the default cumulative probability distribution test input values */
046: public double[] makeCumulativeTestPoints() {
047: // quantiles computed using Mathematica
048: return new double[] { 0.00664355181d, 0.04543282833d,
049: 0.09811627374d, 0.1767135246d, 0.3219468654d,
050: 4.207902826d, 5.23968437d, 6.232056007d, 7.497630467d,
051: 10.51154969d };
052: }
053:
054: /** Creates the default cumulative probability density test expected values */
055: public double[] makeCumulativeTestValues() {
056: return new double[] { 0.001d, 0.01d, 0.025d, 0.05d, 0.1d,
057: 0.900d, 0.950d, 0.975d, 0.990d, 0.999d };
058: }
059:
060: //---------------------------- Additional test cases -------------------------
061:
062: public void testInverseCumulativeProbabilityExtremes()
063: throws Exception {
064: setInverseCumulativeTestPoints(new double[] { 0.0, 1.0 });
065: setInverseCumulativeTestValues(new double[] { 0.0,
066: Double.POSITIVE_INFINITY });
067: verifyInverseCumulativeProbabilities();
068: }
069:
070: public void testAlpha() {
071: WeibullDistribution distribution = (WeibullDistribution) getDistribution();
072: double expected = Math.random();
073: distribution.setShape(expected);
074: assertEquals(expected, distribution.getShape(), 0.0);
075: }
076:
077: public void testBeta() {
078: WeibullDistribution distribution = (WeibullDistribution) getDistribution();
079: double expected = Math.random();
080: distribution.setScale(expected);
081: assertEquals(expected, distribution.getScale(), 0.0);
082: }
083:
084: public void testSetAlpha() {
085: WeibullDistribution distribution = (WeibullDistribution) getDistribution();
086: try {
087: distribution.setShape(0.0);
088: fail("Can not have 0.0 alpha.");
089: } catch (IllegalArgumentException ex) {
090: // success
091: }
092:
093: try {
094: distribution.setShape(-1.0);
095: fail("Can not have negative alpha.");
096: } catch (IllegalArgumentException ex) {
097: // success
098: }
099: }
100:
101: public void testSetBeta() {
102: WeibullDistribution distribution = (WeibullDistribution) getDistribution();
103: try {
104: distribution.setScale(0.0);
105: fail("Can not have 0.0 beta.");
106: } catch (IllegalArgumentException ex) {
107: // success
108: }
109:
110: try {
111: distribution.setScale(-1.0);
112: fail("Can not have negative beta.");
113: } catch (IllegalArgumentException ex) {
114: // success
115: }
116: }
117: }
|