001: /*
002: * Copyright 2003-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.math.distribution;
017:
018: /**
019: * Test cases for BinomialDistribution.
020: * Extends IntegerDistributionAbstractTest. See class javadoc for
021: * IntegerDistributionAbstractTest for details.
022: *
023: * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
024: */
025: public class BinomialDistributionTest extends
026: IntegerDistributionAbstractTest {
027:
028: /**
029: * Constructor for BinomialDistributionTest.
030: * @param name
031: */
032: public BinomialDistributionTest(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: public IntegerDistribution makeDistribution() {
040: return DistributionFactory.newInstance()
041: .createBinomialDistribution(10, 0.70);
042: }
043:
044: /** Creates the default probability density test input values */
045: public int[] makeDensityTestPoints() {
046: return new int[] { -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
047: }
048:
049: /** Creates the default probability density test expected values */
050: public double[] makeDensityTestValues() {
051: return new double[] { 0d, 0.0000d, 0.0001d, 0.0014d, 0.0090d,
052: 0.0368d, 0.1029d, 0.2001d, 0.2668d, 0.2335d, 0.1211d,
053: 0.0282d, 0d };
054: }
055:
056: /** Creates the default cumulative probability density test input values */
057: public int[] makeCumulativeTestPoints() {
058: return makeDensityTestPoints();
059: }
060:
061: /** Creates the default cumulative probability density test expected values */
062: public double[] makeCumulativeTestValues() {
063: return new double[] { 0d, 0.0000d, 0.0001d, 0.0016d, 0.0106d,
064: 0.0473d, 0.1503d, 0.3504d, 0.6172d, 0.8507d, 0.9718d,
065: 1d, 1d };
066: }
067:
068: /** Creates the default inverse cumulative probability test input values */
069: public double[] makeInverseCumulativeTestPoints() {
070: return new double[] { 0, 0.001d, 0.010d, 0.025d, 0.050d,
071: 0.100d, 0.999d, 0.990d, 0.975d, 0.950d, 0.900d, 1 };
072: }
073:
074: /** Creates the default inverse cumulative probability density test expected values */
075: public int[] makeInverseCumulativeTestValues() {
076: return new int[] { -1, 1, 2, 3, 4, 4, 9, 9, 9, 8, 8,
077: Integer.MAX_VALUE };
078: }
079:
080: //----------------- Additional test cases ---------------------------------
081:
082: /** Test degenerate case p = 0 */
083: public void testDegenerate0() throws Exception {
084: setDistribution(DistributionFactory.newInstance()
085: .createBinomialDistribution(5, 0.0d));
086: setCumulativeTestPoints(new int[] { -1, 0, 1, 5, 10 });
087: setCumulativeTestValues(new double[] { 0d, 1d, 1d, 1d, 1d });
088: setDensityTestPoints(new int[] { -1, 0, 1, 10, 11 });
089: setDensityTestValues(new double[] { 0d, 1d, 0d, 0d, 0d });
090: setInverseCumulativeTestPoints(new double[] { 0.1d, 0.5d });
091: setInverseCumulativeTestValues(new int[] { -1, -1 });
092: verifyDensities();
093: verifyCumulativeProbabilities();
094: verifyInverseCumulativeProbabilities();
095: }
096:
097: /** Test degenerate case p = 1 */
098: public void testDegenerate1() throws Exception {
099: setDistribution(DistributionFactory.newInstance()
100: .createBinomialDistribution(5, 1.0d));
101: setCumulativeTestPoints(new int[] { -1, 0, 1, 2, 5, 10 });
102: setCumulativeTestValues(new double[] { 0d, 0d, 0d, 0d, 1d, 1d });
103: setDensityTestPoints(new int[] { -1, 0, 1, 2, 5, 10 });
104: setDensityTestValues(new double[] { 0d, 0d, 0d, 0d, 1d, 0d });
105: setInverseCumulativeTestPoints(new double[] { 0.1d, 0.5d });
106: setInverseCumulativeTestValues(new int[] { 4, 4 });
107: verifyDensities();
108: verifyCumulativeProbabilities();
109: verifyInverseCumulativeProbabilities();
110: }
111:
112: }
|