001: /*
002: * Copyright 2003-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.math.special;
017:
018: import org.apache.commons.math.MathException;
019: import org.apache.commons.math.TestUtils;
020:
021: import junit.framework.TestCase;
022:
023: /**
024: * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
025: */
026: public class BetaTest extends TestCase {
027: /**
028: * Constructor for BetaTest.
029: * @param name
030: */
031: public BetaTest(String name) {
032: super (name);
033: }
034:
035: private void testRegularizedBeta(double expected, double x,
036: double a, double b) {
037: try {
038: double actual = Beta.regularizedBeta(x, a, b);
039: TestUtils.assertEquals(expected, actual, 10e-5);
040: } catch (MathException ex) {
041: fail(ex.getMessage());
042: }
043: }
044:
045: private void testLogBeta(double expected, double a, double b) {
046: double actual = Beta.logBeta(a, b);
047: TestUtils.assertEquals(expected, actual, 10e-5);
048: }
049:
050: public void testRegularizedBetaNanPositivePositive() {
051: testRegularizedBeta(Double.NaN, Double.NaN, 1.0, 1.0);
052: }
053:
054: public void testRegularizedBetaPositiveNanPositive() {
055: testRegularizedBeta(Double.NaN, 0.5, Double.NaN, 1.0);
056: }
057:
058: public void testRegularizedBetaPositivePositiveNan() {
059: testRegularizedBeta(Double.NaN, 0.5, 1.0, Double.NaN);
060: }
061:
062: public void testRegularizedBetaNegativePositivePositive() {
063: testRegularizedBeta(Double.NaN, -0.5, 1.0, 2.0);
064: }
065:
066: public void testRegularizedBetaPositiveNegativePositive() {
067: testRegularizedBeta(Double.NaN, 0.5, -1.0, 2.0);
068: }
069:
070: public void testRegularizedBetaPositivePositiveNegative() {
071: testRegularizedBeta(Double.NaN, 0.5, 1.0, -2.0);
072: }
073:
074: public void testRegularizedBetaZeroPositivePositive() {
075: testRegularizedBeta(0.0, 0.0, 1.0, 2.0);
076: }
077:
078: public void testRegularizedBetaPositiveZeroPositive() {
079: testRegularizedBeta(Double.NaN, 0.5, 0.0, 2.0);
080: }
081:
082: public void testRegularizedBetaPositivePositiveZero() {
083: testRegularizedBeta(Double.NaN, 0.5, 1.0, 0.0);
084: }
085:
086: public void testRegularizedBetaPositivePositivePositive() {
087: testRegularizedBeta(0.75, 0.5, 1.0, 2.0);
088: }
089:
090: public void testLogBetaNanPositive() {
091: testLogBeta(Double.NaN, Double.NaN, 2.0);
092: }
093:
094: public void testLogBetaPositiveNan() {
095: testLogBeta(Double.NaN, 1.0, Double.NaN);
096: }
097:
098: public void testLogBetaNegativePositive() {
099: testLogBeta(Double.NaN, -1.0, 2.0);
100: }
101:
102: public void testLogBetaPositiveNegative() {
103: testLogBeta(Double.NaN, 1.0, -2.0);
104: }
105:
106: public void testLogBetaZeroPositive() {
107: testLogBeta(Double.NaN, 0.0, 2.0);
108: }
109:
110: public void testLogBetaPositiveZero() {
111: testLogBeta(Double.NaN, 1.0, 0.0);
112: }
113:
114: public void testLogBetaPositivePositive() {
115: testLogBeta(-0.693147, 1.0, 2.0);
116: }
117: }
|