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