001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.math.special; 018 019 import org.apache.commons.math.MathException; 020 import org.apache.commons.math.TestUtils; 021 022 import junit.framework.TestCase; 023 024 /** 025 * @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $ 026 */ 027 public class BetaTest extends TestCase { 028 /** 029 * Constructor for BetaTest. 030 * @param name 031 */ 032 public BetaTest(String name) { 033 super(name); 034 } 035 036 private void testRegularizedBeta(double expected, double x, double a, 037 double b) 038 { 039 try { 040 double actual = Beta.regularizedBeta(x, a, b); 041 TestUtils.assertEquals(expected, actual, 10e-15); 042 } catch(MathException ex){ 043 fail(ex.getMessage()); 044 } 045 } 046 047 private void testLogBeta(double expected, double a, double b) { 048 double actual = Beta.logBeta(a, b); 049 TestUtils.assertEquals(expected, actual, 10e-15); 050 } 051 052 public void testRegularizedBetaNanPositivePositive() { 053 testRegularizedBeta(Double.NaN, Double.NaN, 1.0, 1.0); 054 } 055 056 public void testRegularizedBetaPositiveNanPositive() { 057 testRegularizedBeta(Double.NaN, 0.5, Double.NaN, 1.0); 058 } 059 060 public void testRegularizedBetaPositivePositiveNan() { 061 testRegularizedBeta(Double.NaN, 0.5, 1.0, Double.NaN); 062 } 063 064 public void testRegularizedBetaNegativePositivePositive() { 065 testRegularizedBeta(Double.NaN, -0.5, 1.0, 2.0); 066 } 067 068 public void testRegularizedBetaPositiveNegativePositive() { 069 testRegularizedBeta(Double.NaN, 0.5, -1.0, 2.0); 070 } 071 072 public void testRegularizedBetaPositivePositiveNegative() { 073 testRegularizedBeta(Double.NaN, 0.5, 1.0, -2.0); 074 } 075 076 public void testRegularizedBetaZeroPositivePositive() { 077 testRegularizedBeta(0.0, 0.0, 1.0, 2.0); 078 } 079 080 public void testRegularizedBetaPositiveZeroPositive() { 081 testRegularizedBeta(Double.NaN, 0.5, 0.0, 2.0); 082 } 083 084 public void testRegularizedBetaPositivePositiveZero() { 085 testRegularizedBeta(Double.NaN, 0.5, 1.0, 0.0); 086 } 087 088 public void testRegularizedBetaPositivePositivePositive() { 089 testRegularizedBeta(0.75, 0.5, 1.0, 2.0); 090 } 091 092 public void testLogBetaNanPositive() { 093 testLogBeta(Double.NaN, Double.NaN, 2.0); 094 } 095 096 public void testLogBetaPositiveNan() { 097 testLogBeta(Double.NaN, 1.0, Double.NaN); 098 } 099 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 }