001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.math.distribution;
018
019 /**
020 * Test cases for PascalDistribution.
021 * Extends IntegerDistributionAbstractTest. See class javadoc for
022 * IntegerDistributionAbstractTest for details.
023 *
024 * @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
025 */
026 public class PascalDistributionTest extends IntegerDistributionAbstractTest {
027
028 /**
029 * Constructor for PascalDistributionTest.
030 * @param name
031 */
032 public PascalDistributionTest(String name) {
033 super(name);
034 }
035
036 //-------------- Implementations for abstract methods -----------------------
037
038 /** Creates the default discrete distribution instance to use in tests. */
039 @Override
040 public IntegerDistribution makeDistribution() {
041 return new PascalDistributionImpl(10,0.70);
042 }
043
044 /** Creates the default probability density test input values */
045 @Override
046 public int[] makeDensityTestPoints() {
047 return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
048 }
049
050 /** Creates the default probability density test expected values */
051 @Override
052 public double[] makeDensityTestValues() {
053 return new double[] {0d, 0.02824d, 0.08474d, 0.13982d,
054 0.16779d, 0.16359d, 0.1374d, 0.10306d, 0.070673d, 0.04505d, 0.02703d, 0.01540d, 0.0084};
055 }
056
057 /** Creates the default cumulative probability density test input values */
058 @Override
059 public int[] makeCumulativeTestPoints() {
060 return makeDensityTestPoints();
061 }
062
063 /** Creates the default cumulative probability density test expected values */
064 @Override
065 public double[] makeCumulativeTestValues() {
066 return new double[] {0d, 0.02824d, 0.11299d, 0.25281d, 0.42060d, 0.58420d,
067 0.72162d, 0.82468d, 0.89535d, 0.94041d, 0.967446d, 0.98285, 0.99125d};
068 }
069
070 /** Creates the default inverse cumulative probability test input values */
071 @Override
072 public double[] makeInverseCumulativeTestPoints() {
073 return new double[] {0, 0.001d, 0.010d, 0.025d, 0.050d, 0.100d, 0.999d,
074 0.990d, 0.975d, 0.950d, 0.900d, 1};
075 }
076
077 /** Creates the default inverse cumulative probability density test expected values */
078 @Override
079 public int[] makeInverseCumulativeTestValues() {
080 return new int[] {-1, -1, -1, -1, 0, 0, 13, 10, 9, 8, 7, Integer.MAX_VALUE};
081 }
082
083 //----------------- Additional test cases ---------------------------------
084
085 /** Test degenerate case p = 0 */
086 public void testDegenerate0() throws Exception {
087 setDistribution(new PascalDistributionImpl(5,0.0d));
088 setCumulativeTestPoints(new int[] {-1, 0, 1, 5, 10 });
089 setCumulativeTestValues(new double[] {0d, 0d, 0d, 0d, 0d});
090 setDensityTestPoints(new int[] {-1, 0, 1, 10, 11});
091 setDensityTestValues(new double[] {0d, 0d, 0d, 0d, 0d});
092 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
093 setInverseCumulativeTestValues(new int[] {Integer.MAX_VALUE - 1, Integer.MAX_VALUE - 1});
094 verifyDensities();
095 verifyCumulativeProbabilities();
096 verifyInverseCumulativeProbabilities();
097 }
098
099 /** Test degenerate case p = 1 */
100 public void testDegenerate1() throws Exception {
101 setDistribution(new PascalDistributionImpl(5,1.0d));
102 setCumulativeTestPoints(new int[] {-1, 0, 1, 2, 5, 10 });
103 setCumulativeTestValues(new double[] {0d, 1d, 1d, 1d, 1d, 1d});
104 setDensityTestPoints(new int[] {-1, 0, 1, 2, 5, 10});
105 setDensityTestValues(new double[] {0d, 1d, 0d, 0d, 0d, 0d});
106 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
107 setInverseCumulativeTestValues(new int[] {-1, -1});
108 verifyDensities();
109 verifyCumulativeProbabilities();
110 verifyInverseCumulativeProbabilities();
111 }
112 }