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 CauchyDistributionTest extends ContinuousDistributionAbstractTest {
28
29
30
31
32
33 public CauchyDistributionTest(String arg0) {
34 super(arg0);
35 }
36
37
38
39
40 @Override
41 public ContinuousDistribution makeDistribution() {
42 return new CauchyDistributionImpl(1.2, 2.1);
43 }
44
45
46 @Override
47 public double[] makeCumulativeTestPoints() {
48
49 return new double[] {-667.2485619d, -65.6230835d, -25.48302995d,
50 -12.05887818d, -5.263135428d, 7.663135428d, 14.45887818d,
51 27.88302995d, 68.0230835d, 669.6485619d};
52 }
53
54
55 @Override
56 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
61
62
63 public void testInverseCumulativeProbabilityExtremes() throws Exception {
64 setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
65 setInverseCumulativeTestValues(
66 new double[] {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY});
67 verifyInverseCumulativeProbabilities();
68 }
69
70 public void testMedian() {
71 CauchyDistribution distribution = (CauchyDistribution) getDistribution();
72 double expected = Math.random();
73 distribution.setMedian(expected);
74 assertEquals(expected, distribution.getMedian(), 0.0);
75 }
76
77 public void testScale() {
78 CauchyDistribution distribution = (CauchyDistribution) getDistribution();
79 double expected = Math.random();
80 distribution.setScale(expected);
81 assertEquals(expected, distribution.getScale(), 0.0);
82 }
83
84 public void testSetScale() {
85 CauchyDistribution distribution = (CauchyDistribution) getDistribution();
86 try {
87 distribution.setScale(0.0);
88 fail("Can not have 0.0 scale.");
89 } catch (IllegalArgumentException ex) {
90
91 }
92
93 try {
94 distribution.setScale(-1.0);
95 fail("Can not have negative scale.");
96 } catch (IllegalArgumentException ex) {
97
98 }
99 }
100 }