1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.math.distribution;
18
19 import junit.framework.TestCase;
20
21 /**
22 * @version $Revision: 201916 $ $Date: 2005-06-26 15:25:41 -0700 (Sun, 26 Jun 2005) $
23 */
24 public class DistributionFactoryImplTest extends TestCase {
25 /** */
26 private DistributionFactory factory;
27
28 /**
29 * Constructor for DistributionFactoryImplTest.
30 * @param name
31 */
32 public DistributionFactoryImplTest(String name) {
33 super(name);
34 }
35 /**
36 * @throws java.lang.Exception
37 */
38 protected void setUp() throws Exception {
39 super.setUp();
40 factory = new DistributionFactoryImpl();
41 }
42
43 /**
44 * @throws java.lang.Exception
45 */
46 protected void tearDown() throws Exception {
47 factory = null;
48 super.tearDown();
49 }
50
51 public void testCreateChiSquareDistributionNegative(){
52 try {
53 factory.createChiSquareDistribution(-1.0);
54 fail("negative degrees of freedom. IllegalArgumentException expected");
55 } catch (IllegalArgumentException ex) {
56 ;
57 }
58 }
59
60 public void testCreateChiSquareDistributionZero(){
61 try {
62 factory.createChiSquareDistribution(0.0);
63 fail("zero degrees of freedom. IllegalArgumentException expected");
64 } catch (IllegalArgumentException ex) {
65 ;
66 }
67 }
68
69 public void testCreateChiSquareDistributionPositive(){
70 try {
71 factory.createChiSquareDistribution(1.0);
72 } catch (IllegalArgumentException ex) {
73 fail("positive degrees of freedom. IllegalArgumentException is not expected");
74 }
75 }
76
77 public void testCreateFDistributionNegativePositive(){
78 try {
79 factory.createFDistribution(-1.0, 1.0);
80 fail("negative degrees of freedom. IllegalArgumentException expected");
81 } catch (IllegalArgumentException ex) {
82 ;
83 }
84 }
85
86 public void testCreateFDistributionZeroPositive(){
87 try {
88 factory.createFDistribution(0.0, 1.0);
89 fail("zero degrees of freedom. IllegalArgumentException expected");
90 } catch (IllegalArgumentException ex) {
91 ;
92 }
93 }
94
95 public void testCreateFDistributionPositiveNegative(){
96 try {
97 factory.createFDistribution(1.0, -1.0);
98 fail("negative degrees of freedom. IllegalArgumentException expected");
99 } catch (IllegalArgumentException ex) {
100 ;
101 }
102 }
103
104 public void testCreateFDistributionPositiveZero(){
105 try {
106 factory.createFDistribution(1.0, 0.0);
107 fail("zero degrees of freedom. IllegalArgumentException expected");
108 } catch (IllegalArgumentException ex) {
109 ;
110 }
111 }
112
113 public void testCreateFDistributionPositivePositive(){
114 try {
115 factory.createFDistribution(1.0, 1.0);
116 } catch (IllegalArgumentException ex) {
117 fail("positive degrees of freedom. IllegalArgumentException is not expected");
118 }
119 }
120
121 public void testCreateExponentialDistributionNegative(){
122 try {
123 factory.createExponentialDistribution(-1.0);
124 fail("negative mean. IllegalArgumentException expected");
125 } catch (IllegalArgumentException ex) {
126 ;
127 }
128 }
129
130 public void testCreateExponentialDistributionZero(){
131 try {
132 factory.createExponentialDistribution(0.0);
133 fail("zero mean. IllegalArgumentException expected");
134 } catch (IllegalArgumentException ex) {
135 ;
136 }
137 }
138
139 public void testCreateExponentialDistributionPositive(){
140 try {
141 factory.createExponentialDistribution(1.0);
142 } catch (IllegalArgumentException ex) {
143 fail("positive mean. IllegalArgumentException is not expected");
144 }
145 }
146
147 public void testCreateGammaDistributionNegativePositive(){
148 try {
149 factory.createGammaDistribution(-1.0, 1.0);
150 fail("negative alpha. IllegalArgumentException expected");
151 } catch (IllegalArgumentException ex) {
152 ;
153 }
154 }
155
156 public void testCreateGammaDistributionZeroPositive(){
157 try {
158 factory.createGammaDistribution(0.0, 1.0);
159 fail("zero alpha. IllegalArgumentException expected");
160 } catch (IllegalArgumentException ex) {
161 ;
162 }
163 }
164
165 public void testCreateGammaDistributionPositiveNegative(){
166 try {
167 factory.createGammaDistribution(1.0, -1.0);
168 fail("negative beta. IllegalArgumentException expected");
169 } catch (IllegalArgumentException ex) {
170 ;
171 }
172 }
173
174 public void testCreateGammaDistributionPositiveZero(){
175 try {
176 factory.createGammaDistribution(1.0, 0.0);
177 fail("zero beta. IllegalArgumentException expected");
178 } catch (IllegalArgumentException ex) {
179 ;
180 }
181 }
182
183 public void testCreateGammaDistributionPositivePositive(){
184 try {
185 factory.createGammaDistribution(1.0, 1.0);
186 } catch (IllegalArgumentException ex) {
187 fail("positive alpah and beta. IllegalArgumentException is not expected");
188 }
189 }
190
191 public void testCreateTDistributionNegative(){
192 try {
193 factory.createTDistribution(-1.0);
194 fail("negative degrees of freedom. IllegalArgumentException expected");
195 } catch (IllegalArgumentException ex) {
196 ;
197 }
198 }
199
200 public void testCreateTDistributionZero(){
201 try {
202 factory.createTDistribution(0.0);
203 fail("zero degrees of freedom. IllegalArgumentException expected");
204 } catch (IllegalArgumentException ex) {
205 ;
206 }
207 }
208
209 public void testCreateTDistributionPositive(){
210 try {
211 factory.createTDistribution(1.0);
212 } catch (IllegalArgumentException ex) {
213 fail("positive degrees of freedom. IllegalArgumentException is not expected");
214 }
215 }
216
217 public void testBinomialDistributionNegativePositive(){
218 try {
219 factory.createBinomialDistribution(-1, 0.5);
220 fail("negative number of trials. IllegalArgumentException expected");
221 } catch (IllegalArgumentException ex ) {
222 }
223 }
224
225 public void testBinomialDistributionZeroPositive(){
226 try {
227 factory.createBinomialDistribution(0, 0.5);
228 } catch (IllegalArgumentException ex ) {
229 fail("zero number of trials. IllegalArgumentException is not expected");
230 }
231 }
232
233 public void testBinomialDistributionPositivePositive(){
234 try {
235 factory.createBinomialDistribution(10, 0.5);
236 } catch (IllegalArgumentException ex ) {
237 fail("positive number of trials. IllegalArgumentException is not expected");
238 }
239 }
240
241 public void testBinomialDistributionPositiveNegative(){
242 try {
243 factory.createBinomialDistribution(10, -0.5);
244 fail("negative probability of success. IllegalArgumentException expected");
245 } catch (IllegalArgumentException ex ) {
246 }
247 }
248
249 public void testBinomialDistributionPositiveZero(){
250 try {
251 factory.createBinomialDistribution(10, 0.0);
252 } catch (IllegalArgumentException ex ) {
253 fail("zero probability of success. IllegalArgumentException is not expected");
254 }
255 }
256
257 public void testBinomialDistributionPositiveOne(){
258 try {
259 factory.createBinomialDistribution(10, 1.0);
260 } catch (IllegalArgumentException ex ) {
261 fail("valid probability of success. IllegalArgumentException is not expected");
262 }
263 }
264
265 public void testBinomialDistributionPositiveTwo(){
266 try {
267 factory.createBinomialDistribution(10, 2.0);
268 fail("high probability of success. IllegalArgumentException expected");
269 } catch (IllegalArgumentException ex ) {
270 }
271 }
272
273 public void testHypergeometricDistributionNegativePositivePositive(){
274 try {
275 factory.createHypergeometricDistribution(-1, 10, 10);
276 fail("negative population size. IllegalArgumentException expected");
277 } catch(IllegalArgumentException ex) {
278 }
279 }
280
281 public void testHypergeometricDistributionZeroPositivePositive(){
282 try {
283 factory.createHypergeometricDistribution(0, 10, 10);
284 fail("zero population size. IllegalArgumentException expected");
285 } catch(IllegalArgumentException ex) {
286 }
287 }
288
289 public void testHypergeometricDistributionPositiveNegativePositive(){
290 try {
291 factory.createHypergeometricDistribution(20, -1, 10);
292 fail("negative number of successes. IllegalArgumentException expected");
293 } catch(IllegalArgumentException ex) {
294 }
295 }
296
297 public void testHypergeometricDistributionPositiveZeroPositive(){
298 try {
299 factory.createHypergeometricDistribution(20, 0, 10);
300 } catch(IllegalArgumentException ex) {
301 fail("valid number of successes. IllegalArgumentException is not expected");
302 }
303 }
304
305 public void testHypergeometricDistributionPositivePositiveNegative(){
306 try {
307 factory.createHypergeometricDistribution(20, 10, -1);
308 fail("negative sample size. IllegalArgumentException expected");
309 } catch(IllegalArgumentException ex) {
310 }
311 }
312
313 public void testHypergeometricDistributionPositivePositiveZero(){
314 try {
315 factory.createHypergeometricDistribution(20, 10, 0);
316 } catch(IllegalArgumentException ex) {
317 fail("valid sample size. IllegalArgumentException is not expected");
318 }
319 }
320
321 public void testHypergeometricDistributionSmallPopulationSize() {
322 try {
323 factory.createHypergeometricDistribution(5, 3, 10);
324 fail("sample size larger than population size. IllegalArgumentException expected");
325 } catch(IllegalArgumentException ex) {
326 }
327 }
328
329 public void testCauchyDistributionNegative() {
330 try {
331 factory.createCauchyDistribution(0.0, -1.0);
332 fail("invalid scale. IllegalArgumentException expected");
333 } catch(IllegalArgumentException ex) {
334 }
335 }
336
337 public void testCauchyDistributionZero() {
338 try {
339 factory.createCauchyDistribution(0.0, 0.0);
340 fail("invalid scale. IllegalArgumentException expected");
341 } catch(IllegalArgumentException ex) {
342 }
343 }
344
345 public void testWeibullDistributionNegativePositive() {
346 try {
347 factory.createWeibullDistribution(-1.0, 1.0);
348 fail("invalid shape. IllegalArgumentException expected");
349 } catch(IllegalArgumentException ex) {
350 }
351 }
352
353 public void testWeibullDistributionZeroPositive() {
354 try {
355 factory.createWeibullDistribution(0.0, 1.0);
356 fail("invalid shape. IllegalArgumentException expected");
357 } catch(IllegalArgumentException ex) {
358 }
359 }
360
361 public void testWeibullDistributionPositiveNegative() {
362 try {
363 factory.createWeibullDistribution(1.0, -1.0);
364 fail("invalid scale. IllegalArgumentException expected");
365 } catch(IllegalArgumentException ex) {
366 }
367 }
368
369 public void testWeibullDistributionPositiveZero() {
370 try {
371 factory.createWeibullDistribution(1.0, 0.0);
372 fail("invalid scale. IllegalArgumentException expected");
373 } catch(IllegalArgumentException ex) {
374 }
375 }
376 }