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 BinomialDistributionTest extends IntegerDistributionAbstractTest {
27
28
29
30
31
32 public BinomialDistributionTest(String name) {
33 super(name);
34 }
35
36
37
38
39 public IntegerDistribution makeDistribution() {
40 return new BinomialDistributionImpl(10,0.70);
41 }
42
43
44 public int[] makeDensityTestPoints() {
45 return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
46 }
47
48
49 public double[] makeDensityTestValues() {
50 return new double[] {0d, 0.0000d, 0.0001d, 0.0014d, 0.0090d, 0.0368d, 0.1029d,
51 0.2001d, 0.2668d, 0.2335d, 0.1211d, 0.0282d, 0d};
52 }
53
54
55 public int[] makeCumulativeTestPoints() {
56 return makeDensityTestPoints();
57 }
58
59
60 public double[] makeCumulativeTestValues() {
61 return new double[] {0d, 0.0000d, 0.0001d, 0.0016d, 0.0106d, 0.0473d,
62 0.1503d, 0.3504d, 0.6172d, 0.8507d, 0.9718d, 1d, 1d};
63 }
64
65
66 public double[] makeInverseCumulativeTestPoints() {
67 return new double[] {0, 0.001d, 0.010d, 0.025d, 0.050d, 0.100d, 0.999d,
68 0.990d, 0.975d, 0.950d, 0.900d,1};
69 }
70
71
72 public int[] makeInverseCumulativeTestValues() {
73 return new int[] {-1, 1, 2, 3, 4, 4, 9, 9, 9, 8, 8, Integer.MAX_VALUE};
74 }
75
76
77
78
79 public void testDegenerate0() throws Exception {
80 setDistribution(new BinomialDistributionImpl(5,0.0d));
81 setCumulativeTestPoints(new int[] {-1, 0, 1, 5, 10 });
82 setCumulativeTestValues(new double[] {0d, 1d, 1d, 1d, 1d});
83 setDensityTestPoints(new int[] {-1, 0, 1, 10, 11});
84 setDensityTestValues(new double[] {0d, 1d, 0d, 0d, 0d});
85 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
86 setInverseCumulativeTestValues(new int[] {-1, -1});
87 verifyDensities();
88 verifyCumulativeProbabilities();
89 verifyInverseCumulativeProbabilities();
90 }
91
92
93 public void testDegenerate1() throws Exception {
94 setDistribution(new BinomialDistributionImpl(5,1.0d));
95 setCumulativeTestPoints(new int[] {-1, 0, 1, 2, 5, 10 });
96 setCumulativeTestValues(new double[] {0d, 0d, 0d, 0d, 1d, 1d});
97 setDensityTestPoints(new int[] {-1, 0, 1, 2, 5, 10});
98 setDensityTestValues(new double[] {0d, 0d, 0d, 0d, 1d, 0d});
99 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
100 setInverseCumulativeTestValues(new int[] {4, 4});
101 verifyDensities();
102 verifyCumulativeProbabilities();
103 verifyInverseCumulativeProbabilities();
104 }
105
106 }