1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.math.special;
18
19 import org.apache.commons.math.MathException;
20 import org.apache.commons.math.TestUtils;
21
22 import junit.framework.TestCase;
23
24
25
26
27 public class BetaTest extends TestCase {
28
29
30
31
32 public BetaTest(String name) {
33 super(name);
34 }
35
36 private void testRegularizedBeta(double expected, double x, double a,
37 double b)
38 {
39 try {
40 double actual = Beta.regularizedBeta(x, a, b);
41 TestUtils.assertEquals(expected, actual, 10e-15);
42 } catch(MathException ex){
43 fail(ex.getMessage());
44 }
45 }
46
47 private void testLogBeta(double expected, double a, double b) {
48 double actual = Beta.logBeta(a, b);
49 TestUtils.assertEquals(expected, actual, 10e-15);
50 }
51
52 public void testRegularizedBetaNanPositivePositive() {
53 testRegularizedBeta(Double.NaN, Double.NaN, 1.0, 1.0);
54 }
55
56 public void testRegularizedBetaPositiveNanPositive() {
57 testRegularizedBeta(Double.NaN, 0.5, Double.NaN, 1.0);
58 }
59
60 public void testRegularizedBetaPositivePositiveNan() {
61 testRegularizedBeta(Double.NaN, 0.5, 1.0, Double.NaN);
62 }
63
64 public void testRegularizedBetaNegativePositivePositive() {
65 testRegularizedBeta(Double.NaN, -0.5, 1.0, 2.0);
66 }
67
68 public void testRegularizedBetaPositiveNegativePositive() {
69 testRegularizedBeta(Double.NaN, 0.5, -1.0, 2.0);
70 }
71
72 public void testRegularizedBetaPositivePositiveNegative() {
73 testRegularizedBeta(Double.NaN, 0.5, 1.0, -2.0);
74 }
75
76 public void testRegularizedBetaZeroPositivePositive() {
77 testRegularizedBeta(0.0, 0.0, 1.0, 2.0);
78 }
79
80 public void testRegularizedBetaPositiveZeroPositive() {
81 testRegularizedBeta(Double.NaN, 0.5, 0.0, 2.0);
82 }
83
84 public void testRegularizedBetaPositivePositiveZero() {
85 testRegularizedBeta(Double.NaN, 0.5, 1.0, 0.0);
86 }
87
88 public void testRegularizedBetaPositivePositivePositive() {
89 testRegularizedBeta(0.75, 0.5, 1.0, 2.0);
90 }
91
92 public void testLogBetaNanPositive() {
93 testLogBeta(Double.NaN, Double.NaN, 2.0);
94 }
95
96 public void testLogBetaPositiveNan() {
97 testLogBeta(Double.NaN, 1.0, Double.NaN);
98 }
99
100 public void testLogBetaNegativePositive() {
101 testLogBeta(Double.NaN, -1.0, 2.0);
102 }
103
104 public void testLogBetaPositiveNegative() {
105 testLogBeta(Double.NaN, 1.0, -2.0);
106 }
107
108 public void testLogBetaZeroPositive() {
109 testLogBeta(Double.NaN, 0.0, 2.0);
110 }
111
112 public void testLogBetaPositiveZero() {
113 testLogBeta(Double.NaN, 1.0, 0.0);
114 }
115
116 public void testLogBetaPositivePositive() {
117 testLogBeta(-0.693147180559945, 1.0, 2.0);
118 }
119 }