1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math.distribution;
19
20
21
22
23
24
25
26
27 public class WeibullDistributionTest extends ContinuousDistributionAbstractTest {
28
29
30
31
32
33 public WeibullDistributionTest(String arg0) {
34 super(arg0);
35 }
36
37
38
39
40 public ContinuousDistribution makeDistribution() {
41 return new WeibullDistributionImpl(1.2, 2.1);
42 }
43
44
45 public double[] makeCumulativeTestPoints() {
46
47 return new double[] {0.00664355181d, 0.04543282833d, 0.09811627374d,
48 0.1767135246d, 0.3219468654d, 4.207902826d, 5.23968437d,
49 6.232056007d, 7.497630467d, 10.51154969d};
50 }
51
52
53 public double[] makeCumulativeTestValues() {
54 return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.900d, 0.950d,
55 0.975d, 0.990d, 0.999d};
56 }
57
58
59
60 public void testInverseCumulativeProbabilityExtremes() throws Exception {
61 setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
62 setInverseCumulativeTestValues(
63 new double[] {0.0, Double.POSITIVE_INFINITY});
64 verifyInverseCumulativeProbabilities();
65 }
66
67 public void testAlpha() {
68 WeibullDistribution distribution = (WeibullDistribution) getDistribution();
69 double expected = Math.random();
70 distribution.setShape(expected);
71 assertEquals(expected, distribution.getShape(), 0.0);
72 }
73
74 public void testBeta() {
75 WeibullDistribution distribution = (WeibullDistribution) getDistribution();
76 double expected = Math.random();
77 distribution.setScale(expected);
78 assertEquals(expected, distribution.getScale(), 0.0);
79 }
80
81 public void testSetAlpha() {
82 WeibullDistribution distribution = (WeibullDistribution) getDistribution();
83 try {
84 distribution.setShape(0.0);
85 fail("Can not have 0.0 alpha.");
86 } catch (IllegalArgumentException ex) {
87
88 }
89
90 try {
91 distribution.setShape(-1.0);
92 fail("Can not have negative alpha.");
93 } catch (IllegalArgumentException ex) {
94
95 }
96 }
97
98 public void testSetBeta() {
99 WeibullDistribution distribution = (WeibullDistribution) getDistribution();
100 try {
101 distribution.setScale(0.0);
102 fail("Can not have 0.0 beta.");
103 } catch (IllegalArgumentException ex) {
104
105 }
106
107 try {
108 distribution.setScale(-1.0);
109 fail("Can not have negative beta.");
110 } catch (IllegalArgumentException ex) {
111
112 }
113 }
114 }