1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.distribution.discrete;
23
24 import org.hipparchus.distribution.IntegerDistribution;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27
28 import static org.junit.jupiter.api.Assertions.assertEquals;
29
30
31
32
33 public class PascalDistributionTest extends IntegerDistributionAbstractTest {
34
35
36 protected double defaultTolerance = 1e-9;
37
38 @BeforeEach
39 @Override
40 public void setUp() {
41 super.setUp();
42 setTolerance(defaultTolerance);
43 }
44
45
46
47
48 @Override
49 public IntegerDistribution makeDistribution() {
50 return new PascalDistribution(10,0.70);
51 }
52
53
54 @Override
55 public int[] makeDensityTestPoints() {
56 return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
57 }
58
59
60 @Override
61 public double[] makeDensityTestValues() {
62 return new double[] {0, 0.0282475249, 0.0847425747, 0.139825248255, 0.167790297906, 0.163595540458,
63 0.137420253985, 0.103065190489, 0.070673273478, 0.0450542118422, 0.0270325271053,
64 0.0154085404500, 0.0084046584273};
65 }
66
67
68 @Override
69 public int[] makeCumulativeTestPoints() {
70 return makeDensityTestPoints();
71 }
72
73
74 @Override
75 public double[] makeCumulativeTestValues() {
76 return new double[] {0, 0.0282475249, 0.1129900996, 0.252815347855, 0.420605645761, 0.584201186219,
77 0.721621440204, 0.824686630693, 0.895359904171, 0.940414116013, 0.967446643119,
78 0.982855183569, 0.991259841996};
79 }
80
81
82 @Override
83 public double[] makeInverseCumulativeTestPoints() {
84 return new double[] {0.0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999,
85 0.990, 0.975, 0.950, 0.900, 1.0};
86 }
87
88
89 @Override
90 public int[] makeInverseCumulativeTestValues() {
91 return new int[] {0, 0, 0, 0, 1, 1, 14, 11, 10, 9, 8, Integer.MAX_VALUE};
92 }
93
94
95
96
97 @Test
98 void testDegenerate0() {
99 setDistribution(new PascalDistribution(5, 0.0d));
100 setCumulativeTestPoints(new int[] {-1, 0, 1, 5, 10 });
101 setCumulativeTestValues(new double[] {0d, 0d, 0d, 0d, 0d});
102 setDensityTestPoints(new int[] {-1, 0, 1, 10, 11});
103 setDensityTestValues(new double[] {0d, 0d, 0d, 0d, 0d});
104 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
105 setInverseCumulativeTestValues(new int[] {Integer.MAX_VALUE, Integer.MAX_VALUE});
106 verifyDensities();
107 verifyCumulativeProbabilities();
108 verifyInverseCumulativeProbabilities();
109 }
110
111
112 @Test
113 void testDegenerate1() {
114 setDistribution(new PascalDistribution(5, 1.0d));
115 setCumulativeTestPoints(new int[] {-1, 0, 1, 2, 5, 10 });
116 setCumulativeTestValues(new double[] {0d, 1d, 1d, 1d, 1d, 1d});
117 setDensityTestPoints(new int[] {-1, 0, 1, 2, 5, 10});
118 setDensityTestValues(new double[] {0d, 1d, 0d, 0d, 0d, 0d});
119 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
120 setInverseCumulativeTestValues(new int[] {0, 0});
121 verifyDensities();
122 verifyCumulativeProbabilities();
123 verifyInverseCumulativeProbabilities();
124 }
125
126 @Test
127 void testMoments() {
128 final double tol = 1e-9;
129 PascalDistribution dist;
130
131 dist = new PascalDistribution(10, 0.5);
132 assertEquals(dist.getNumericalMean(), ( 10d * 0.5d ) / 0.5d, tol);
133 assertEquals(dist.getNumericalVariance(), ( 10d * 0.5d ) / (0.5d * 0.5d), tol);
134
135 dist = new PascalDistribution(25, 0.7);
136 assertEquals(dist.getNumericalMean(), ( 25d * 0.3d ) / 0.7d, tol);
137 assertEquals(dist.getNumericalVariance(), ( 25d * 0.3d ) / (0.7d * 0.7d), tol);
138 }
139 }