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