~ubuntu-branches/ubuntu/quantal/commons-math/quantal

« back to all changes in this revision

Viewing changes to src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2010-04-05 23:33:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100405233302-gpqlceked76nw28a
Tags: 2.1-1
* New upstream release.
* Bump Standards-Version to 3.8.4: no changes needed
* Bump debhelper to >= 7
* Switch to 3.0 (quilt) source format:
  - Remove B-D on quilt
  - Add d/source/format
  - Remove d/README.source

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * Test cases for WeibullDistribution.
22
22
 * Extends ContinuousDistributionAbstractTest.  See class javadoc for
23
23
 * ContinuousDistributionAbstractTest for details.
24
 
 * 
25
 
 * @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
 
24
 *
 
25
 * @version $Revision: 924362 $ $Date: 2010-03-17 12:45:31 -0400 (Wed, 17 Mar 2010) $
26
26
 */
27
27
public class WeibullDistributionTest extends ContinuousDistributionAbstractTest  {
28
 
    
 
28
 
29
29
    /**
30
30
     * Constructor for CauchyDistributionTest.
31
31
     * @param arg0
33
33
    public WeibullDistributionTest(String arg0) {
34
34
        super(arg0);
35
35
    }
36
 
    
 
36
 
37
37
    //-------------- Implementations for abstract methods -----------------------
38
 
    
 
38
 
39
39
    /** Creates the default continuous distribution instance to use in tests. */
40
40
    @Override
41
 
    public ContinuousDistribution makeDistribution() {
 
41
    public WeibullDistribution makeDistribution() {
42
42
        return new WeibullDistributionImpl(1.2, 2.1);
43
 
    }   
44
 
    
 
43
    }
 
44
 
45
45
    /** Creates the default cumulative probability distribution test input values */
46
46
    @Override
47
47
    public double[] makeCumulativeTestPoints() {
48
 
        // quantiles computed using Mathematica 
49
 
        return new double[] {0.00664355181d, 0.04543282833d, 0.09811627374d,
50
 
                0.1767135246d, 0.3219468654d, 4.207902826d, 5.23968437d,
51
 
                6.232056007d, 7.497630467d, 10.51154969d};
 
48
        // quantiles computed using R version 2.9.2
 
49
        return new double[] {0.00664355180993, 0.0454328283309, 0.0981162737374, 0.176713524579, 0.321946865392,
 
50
                10.5115496887, 7.4976304671, 6.23205600701, 5.23968436955, 4.2079028257};
52
51
    }
53
 
    
 
52
 
54
53
    /** Creates the default cumulative probability density test expected values */
55
54
    @Override
56
55
    public double[] makeCumulativeTestValues() {
57
 
        return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.900d, 0.950d,
58
 
                0.975d, 0.990d, 0.999d};
59
 
    }
60
 
    
 
56
        return new double[] {0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900};
 
57
    }
 
58
 
 
59
    /** Creates the default probability density test expected values */
 
60
    @Override
 
61
    public double[] makeDensityTestValues() {
 
62
        return new double[] {0.180535929306, 0.262801138133, 0.301905425199, 0.330899152971,
 
63
          0.353441418887, 0.000788590320203, 0.00737060094841, 0.0177576041516, 0.0343043442574, 0.065664589369};
 
64
    }
 
65
 
61
66
    //---------------------------- Additional test cases -------------------------
62
 
    
 
67
 
63
68
    public void testInverseCumulativeProbabilityExtremes() throws Exception {
64
69
        setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
65
70
        setInverseCumulativeTestValues(
66
71
                new double[] {0.0, Double.POSITIVE_INFINITY});
67
72
        verifyInverseCumulativeProbabilities();
68
73
    }
69
 
    
 
74
 
70
75
    public void testAlpha() {
71
76
        WeibullDistribution distribution = (WeibullDistribution) getDistribution();
72
77
        double expected = Math.random();
73
78
        distribution.setShape(expected);
74
79
        assertEquals(expected, distribution.getShape(), 0.0);
75
80
    }
76
 
    
 
81
 
77
82
    public void testBeta() {
78
83
        WeibullDistribution distribution = (WeibullDistribution) getDistribution();
79
84
        double expected = Math.random();
80
85
        distribution.setScale(expected);
81
86
        assertEquals(expected, distribution.getScale(), 0.0);
82
87
    }
83
 
    
 
88
 
84
89
    public void testSetAlpha() {
85
90
        WeibullDistribution distribution = (WeibullDistribution) getDistribution();
86
91
        try {
89
94
        } catch (IllegalArgumentException ex) {
90
95
            // success
91
96
        }
92
 
        
 
97
 
93
98
        try {
94
99
            distribution.setShape(-1.0);
95
100
            fail("Can not have negative alpha.");
97
102
            // success
98
103
        }
99
104
    }
100
 
    
 
105
 
101
106
    public void testSetBeta() {
102
107
        WeibullDistribution distribution = (WeibullDistribution) getDistribution();
103
108
        try {
106
111
        } catch (IllegalArgumentException ex) {
107
112
            // success
108
113
        }
109
 
        
 
114
 
110
115
        try {
111
116
            distribution.setScale(-1.0);
112
117
            fail("Can not have negative beta.");