1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.stat.interval;
23
24 import org.hipparchus.exception.MathIllegalArgumentException;
25 import org.junit.Before;
26 import org.junit.Test;
27
28
29
30
31 public abstract class BinomialProportionAbstractTest {
32
33 @FunctionalInterface
34 public interface BinomialProportionMethod {
35 ConfidenceInterval calculate(int trials, double probability, double confidenceLevel);
36 }
37
38 protected BinomialProportionMethod testMethod;
39
40 private final int trials = 500;
41 private final double probabilityOfSuccess = 0.1;
42 private final double confidenceLevel = 0.9;
43
44 protected abstract BinomialProportionMethod getBinomialProportionMethod();
45
46
47
48
49
50
51
52
53
54
55
56 protected ConfidenceInterval createStandardTestInterval() {
57 return testMethod.calculate(trials, probabilityOfSuccess, confidenceLevel);
58 }
59
60 @Before
61 public void setUp() {
62 testMethod = getBinomialProportionMethod();
63 }
64
65 @Test(expected = MathIllegalArgumentException.class)
66 public void testZeroConfidencelevel() {
67 testMethod.calculate(trials, probabilityOfSuccess, 0d);
68 }
69
70 @Test(expected = MathIllegalArgumentException.class)
71 public void testOneConfidencelevel() {
72 testMethod.calculate(trials, probabilityOfSuccess, 1d);
73 }
74
75 @Test(expected = MathIllegalArgumentException.class)
76 public void testZeroTrials() {
77 testMethod.calculate(0, 0, confidenceLevel);
78 }
79
80 @Test(expected = MathIllegalArgumentException.class)
81 public void testNegativeSuccesses() {
82 testMethod.calculate(trials, -1, confidenceLevel);
83 }
84
85 @Test(expected = MathIllegalArgumentException.class)
86 public void testSuccessesExceedingTrials() {
87 testMethod.calculate(trials, trials + 1, confidenceLevel);
88 }
89 }