~ubuntu-branches/ubuntu/natty/commons-math/natty

« back to all changes in this revision

Viewing changes to src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2010-04-05 23:33:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100405233302-gpqlceked76nw28a
Tags: 2.1-1
* New upstream release.
* Bump Standards-Version to 3.8.4: no changes needed
* Bump debhelper to >= 7
* Switch to 3.0 (quilt) source format:
  - Remove B-D on quilt
  - Add d/source/format
  - Remove d/README.source

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
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
8
 
 * 
9
 
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 
 * 
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.
 
3
 * contributor license agreements. See the NOTICE file distributed with this
 
4
 * work for additional information regarding copyright ownership. The ASF
 
5
 * licenses this file to You under the Apache License, Version 2.0 (the
 
6
 * "License"); you may not use this file except in compliance with the License.
 
7
 * You may obtain a copy of the License at
 
8
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 
9
 * or agreed to in writing, software distributed under the License is
 
10
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
11
 * KIND, either express or implied. See the License for the specific language
 
12
 * governing permissions and limitations under the License.
16
13
 */
17
14
package org.apache.commons.math.distribution;
18
15
 
19
16
/**
20
 
 * Test cases for BinomialDistribution.
21
 
 * Extends IntegerDistributionAbstractTest.  See class javadoc for
22
 
 * IntegerDistributionAbstractTest for details.
23
 
 * 
24
 
 * @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
 
17
 * Test cases for BinomialDistribution. Extends IntegerDistributionAbstractTest.
 
18
 * See class javadoc for IntegerDistributionAbstractTest for details.
 
19
 *
 
20
 * @version $Revision: 924345 $ $Date: 2009-09-05 12:36:48 -0500 (Sat, 05 Sep
 
21
 *          2009) $
25
22
 */
26
23
public class BinomialDistributionTest extends IntegerDistributionAbstractTest {
27
 
    
 
24
 
28
25
    /**
29
26
     * Constructor for BinomialDistributionTest.
 
27
     *
30
28
     * @param name
31
29
     */
32
30
    public BinomialDistributionTest(String name) {
33
31
        super(name);
34
32
    }
35
 
    
36
 
    //-------------- Implementations for abstract methods -----------------------
37
 
    
 
33
 
 
34
    // -------------- Implementations for abstract methods
 
35
    // -----------------------
 
36
 
38
37
    /** Creates the default discrete distribution instance to use in tests. */
39
38
    @Override
40
39
    public IntegerDistribution makeDistribution() {
41
 
        return new BinomialDistributionImpl(10,0.70);
 
40
        return new BinomialDistributionImpl(10, 0.70);
42
41
    }
43
 
    
 
42
 
44
43
    /** Creates the default probability density test input values */
45
44
    @Override
46
45
    public int[] makeDensityTestPoints() {
47
 
        return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
 
46
        return new int[] { -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
48
47
    }
49
 
    
 
48
 
50
49
    /** Creates the default probability density test expected values */
51
50
    @Override
52
51
    public double[] makeDensityTestValues() {
53
 
        return new double[] {0d, 0.0000d, 0.0001d, 0.0014d, 0.0090d, 0.0368d, 0.1029d, 
54
 
                0.2001d, 0.2668d, 0.2335d, 0.1211d, 0.0282d, 0d};
 
52
        return new double[] { 0d, 0.0000059049d, 0.000137781d, 0.0014467d,
 
53
                0.00900169d, 0.0367569d, 0.102919d, 0.200121d, 0.266828d,
 
54
                0.233474d, 0.121061d, 0.0282475d, 0d };
55
55
    }
56
 
    
 
56
 
57
57
    /** Creates the default cumulative probability density test input values */
58
58
    @Override
59
59
    public int[] makeCumulativeTestPoints() {
60
60
        return makeDensityTestPoints();
61
61
    }
62
 
    
 
62
 
63
63
    /** Creates the default cumulative probability density test expected values */
64
64
    @Override
65
65
    public double[] makeCumulativeTestValues() {
66
 
        return new double[] {0d, 0.0000d, 0.0001d, 0.0016d, 0.0106d, 0.0473d,
67
 
                0.1503d, 0.3504d, 0.6172d, 0.8507d, 0.9718d, 1d, 1d};
68
 
        }
69
 
    
 
66
        return new double[] { 0d, 0.0000d, 0.0001d, 0.0016d, 0.0106d, 0.0473d,
 
67
                0.1503d, 0.3504d, 0.6172d, 0.8507d, 0.9718d, 1d, 1d };
 
68
    }
 
69
 
70
70
    /** Creates the default inverse cumulative probability test input values */
71
71
    @Override
72
72
    public double[] makeInverseCumulativeTestPoints() {
73
 
        return new double[] {0, 0.001d, 0.010d, 0.025d, 0.050d, 0.100d, 0.999d,
74
 
                0.990d, 0.975d, 0.950d, 0.900d,1}; 
75
 
        }
76
 
    
77
 
    /** Creates the default inverse cumulative probability density test expected values */
 
73
        return new double[] { 0, 0.001d, 0.010d, 0.025d, 0.050d, 0.100d,
 
74
                0.999d, 0.990d, 0.975d, 0.950d, 0.900d, 1 };
 
75
    }
 
76
 
 
77
    /**
 
78
     * Creates the default inverse cumulative probability density test expected
 
79
     * values
 
80
     */
78
81
    @Override
79
82
    public int[] makeInverseCumulativeTestValues() {
80
 
        return new int[] {-1, 1, 2, 3, 4, 4, 9, 9, 9, 8, 8, Integer.MAX_VALUE};
 
83
        return new int[] { -1, 1, 2, 3, 4, 4, 9, 9, 9, 8, 8, Integer.MAX_VALUE };
81
84
    }
82
85
 
83
 
    //----------------- Additional test cases ---------------------------------
84
 
   
85
 
    /** Test degenerate case p = 0   */
 
86
    // ----------------- Additional test cases ---------------------------------
 
87
 
 
88
    /** Test degenerate case p = 0 */
86
89
    public void testDegenerate0() throws Exception {
87
 
        setDistribution(new BinomialDistributionImpl(5,0.0d));
88
 
        setCumulativeTestPoints(new int[] {-1, 0, 1, 5, 10 });
89
 
        setCumulativeTestValues(new double[] {0d, 1d, 1d, 1d, 1d});
90
 
        setDensityTestPoints(new int[] {-1, 0, 1, 10, 11});
91
 
        setDensityTestValues(new double[] {0d, 1d, 0d, 0d, 0d});
92
 
        setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
93
 
        setInverseCumulativeTestValues(new int[] {-1, -1});
 
90
        setDistribution(new BinomialDistributionImpl(5, 0.0d));
 
91
        setCumulativeTestPoints(new int[] { -1, 0, 1, 5, 10 });
 
92
        setCumulativeTestValues(new double[] { 0d, 1d, 1d, 1d, 1d });
 
93
        setDensityTestPoints(new int[] { -1, 0, 1, 10, 11 });
 
94
        setDensityTestValues(new double[] { 0d, 1d, 0d, 0d, 0d });
 
95
        setInverseCumulativeTestPoints(new double[] { 0.1d, 0.5d });
 
96
        setInverseCumulativeTestValues(new int[] { -1, -1 });
94
97
        verifyDensities();
95
98
        verifyCumulativeProbabilities();
96
 
        verifyInverseCumulativeProbabilities();     
 
99
        verifyInverseCumulativeProbabilities();
97
100
    }
98
 
    
99
 
    /** Test degenerate case p = 1   */
 
101
 
 
102
    /** Test degenerate case p = 1 */
100
103
    public void testDegenerate1() throws Exception {
101
 
        setDistribution(new BinomialDistributionImpl(5,1.0d));
102
 
        setCumulativeTestPoints(new int[] {-1, 0, 1, 2, 5, 10 });
103
 
        setCumulativeTestValues(new double[] {0d, 0d, 0d, 0d, 1d, 1d});
104
 
        setDensityTestPoints(new int[] {-1, 0, 1, 2, 5, 10});
105
 
        setDensityTestValues(new double[] {0d, 0d, 0d, 0d, 1d, 0d});
106
 
        setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d});
107
 
        setInverseCumulativeTestValues(new int[] {4, 4});
 
104
        setDistribution(new BinomialDistributionImpl(5, 1.0d));
 
105
        setCumulativeTestPoints(new int[] { -1, 0, 1, 2, 5, 10 });
 
106
        setCumulativeTestValues(new double[] { 0d, 0d, 0d, 0d, 1d, 1d });
 
107
        setDensityTestPoints(new int[] { -1, 0, 1, 2, 5, 10 });
 
108
        setDensityTestValues(new double[] { 0d, 0d, 0d, 0d, 1d, 0d });
 
109
        setInverseCumulativeTestPoints(new double[] { 0.1d, 0.5d });
 
110
        setInverseCumulativeTestValues(new int[] { 4, 4 });
108
111
        verifyDensities();
109
112
        verifyCumulativeProbabilities();
110
 
        verifyInverseCumulativeProbabilities();     
 
113
        verifyInverseCumulativeProbabilities();
111
114
    }
112
115
 
113
116
}