2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.math.distribution;
20
* Test cases for PascalDistribution.
21
* Extends IntegerDistributionAbstractTest. See class javadoc for
22
* IntegerDistributionAbstractTest for details.
24
* @version $Revision:$ $Date:$
26
public class PascalDistributionTest extends IntegerDistributionAbstractTest {
29
* Constructor for PascalDistributionTest.
32
public PascalDistributionTest(String name) {
36
//-------------- Implementations for abstract methods -----------------------
38
/** Creates the default discrete distribution instance to use in tests. */
39
public IntegerDistribution makeDistribution() {
40
return new PascalDistributionImpl(10,0.70);
43
/** Creates the default probability density test input values */
44
public int[] makeDensityTestPoints() {
45
return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
48
/** Creates the default probability density test expected values */
49
public double[] makeDensityTestValues() {
50
return new double[] {0d, 0.02824d, 0.08474d, 0.13982d,
51
0.16779d, 0.16359d, 0.1374d, 0.10306d, 0.070673d, 0.04505d, 0.02703d, 0.01540d, 0.0084};
54
/** Creates the default cumulative probability density test input values */
55
public int[] makeCumulativeTestPoints() {
56
return makeDensityTestPoints();
59
/** Creates the default cumulative probability density test expected values */
60
public double[] makeCumulativeTestValues() {
61
return new double[] {0d, 0.02824d, 0.11299d, 0.25281d, 0.42060d, 0.58420d,
62
0.72162d, 0.82468d, 0.89535d, 0.94041d, 0.967446d, 0.98285, 0.99125d};
65
/** Creates the default inverse cumulative probability test input values */
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};
71
/** Creates the default inverse cumulative probability density test expected values */
72
public int[] makeInverseCumulativeTestValues() {
73
return new int[] {-1, -1, -1, -1, 0, 0, 13, 10, 9, 8, 7, Integer.MAX_VALUE};
76
//----------------- Additional test cases ---------------------------------
78
/** Test degenerate case p = 0 */
79
public void testDegenerate0() throws Exception {
80
setDistribution(new PascalDistributionImpl(5,0.0d));
81
setCumulativeTestPoints(new int[] {-1, 0, 1, 5, 10 });
82
setCumulativeTestValues(new double[] {0d, 0d, 0d, 0d, 0d});
83
setDensityTestPoints(new int[] {-1, 0, 1, 10, 11});
84
setDensityTestValues(new double[] {0d, 0d, 0d, 0d, 0d});
85
setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
86
setInverseCumulativeTestValues(new int[] {Integer.MAX_VALUE - 1, Integer.MAX_VALUE - 1});
88
verifyCumulativeProbabilities();
89
verifyInverseCumulativeProbabilities();
92
/** Test degenerate case p = 1 */
93
public void testDegenerate1() throws Exception {
94
setDistribution(new PascalDistributionImpl(5,1.0d));
95
setCumulativeTestPoints(new int[] {-1, 0, 1, 2, 5, 10 });
96
setCumulativeTestValues(new double[] {0d, 1d, 1d, 1d, 1d, 1d});
97
setDensityTestPoints(new int[] {-1, 0, 1, 2, 5, 10});
98
setDensityTestValues(new double[] {0d, 1d, 0d, 0d, 0d, 0d});
99
setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
100
setInverseCumulativeTestValues(new int[] {-1, -1});
102
verifyCumulativeProbabilities();
103
verifyInverseCumulativeProbabilities();