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.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   * @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $
26   */
27  public class BetaTest extends TestCase {
28      /**
29       * Constructor for BetaTest.
30       * @param name
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 }