View Javadoc
1   /*
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.
16   */
17  package org.apache.commons.math4.legacy.stat.interval;
18  
19  import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
20  import org.junit.Before;
21  import org.junit.Test;
22  
23  /**
24   * Test cases for the BinomialConfidenceInterval implementations.
25   *
26   */
27  public abstract class BinomialConfidenceIntervalAbstractTest {
28  
29      protected BinomialConfidenceInterval testStatistic;
30  
31      private final int successes = 50;
32      private final int trials = 500;
33      private final double confidenceLevel = 0.9;
34  
35      protected abstract BinomialConfidenceInterval createBinomialConfidenceInterval();
36  
37      /**
38       * Returns the confidence interval for the given statistic with the following values:
39       *
40       * <ul>
41       *  <li>trials: 500</li>
42       *  <li>successes: 50</li>
43       *  <li>confidenceLevel: 0.9</li>
44       * </ul>
45       * @return the Confidence Interval for the given values
46       */
47      protected ConfidenceInterval createStandardTestInterval() {
48          return testStatistic.createInterval(trials, successes, confidenceLevel);
49      }
50  
51      @Before
52      public void setUp() {
53          testStatistic = createBinomialConfidenceInterval();
54      }
55  
56      @Test(expected = MathIllegalArgumentException.class)
57      public void testZeroConfidencelevel() {
58          testStatistic.createInterval(trials, successes, 0d);
59      }
60  
61      @Test(expected = MathIllegalArgumentException.class)
62      public void testOneConfidencelevel() {
63          testStatistic.createInterval(trials, successes, 1d);
64      }
65  
66      @Test(expected = MathIllegalArgumentException.class)
67      public void testZeroTrials() {
68          testStatistic.createInterval(0, 0, confidenceLevel);
69      }
70  
71      @Test(expected = MathIllegalArgumentException.class)
72      public void testNegativeSuccesses() {
73          testStatistic.createInterval(trials, -1, confidenceLevel);
74      }
75  
76      @Test(expected = MathIllegalArgumentException.class)
77      public void testSuccessesExceedingTrials() {
78          testStatistic.createInterval(trials, trials + 1, confidenceLevel);
79      }
80  }