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 GammaTest extends TestCase { 27 31 public GammaTest(String name) { 32 super(name); 33 } 34 35 private void testRegularizedGamma(double expected, double a, double x) { 36 try { 37 double actualP = Gamma.regularizedGammaP(a, x); 38 double actualQ = Gamma.regularizedGammaQ(a, x); 39 TestUtils.assertEquals(expected, actualP, 10e-5); 40 TestUtils.assertEquals(actualP, 1.0 - actualQ, 10e-5); 41 } catch(MathException ex){ 42 fail(ex.getMessage()); 43 } 44 } 45 46 private void testLogGamma(double expected, double x) { 47 double actual = Gamma.logGamma(x); 48 TestUtils.assertEquals(expected, actual, 10e-5); 49 } 50 51 public void testRegularizedGammaNanPositive() { 52 testRegularizedGamma(Double.NaN, Double.NaN, 1.0); 53 } 54 55 public void testRegularizedGammaPositiveNan() { 56 testRegularizedGamma(Double.NaN, 1.0, Double.NaN); 57 } 58 59 public void testRegularizedGammaNegativePositive() { 60 testRegularizedGamma(Double.NaN, -1.5, 1.0); 61 } 62 63 public void testRegularizedGammaPositiveNegative() { 64 testRegularizedGamma(Double.NaN, 1.0, -1.0); 65 } 66 67 public void testRegularizedGammaZeroPositive() { 68 testRegularizedGamma(Double.NaN, 0.0, 1.0); 69 } 70 71 public void testRegularizedGammaPositiveZero() { 72 testRegularizedGamma(0.0, 1.0, 0.0); 73 } 74 75 public void testRegularizedGammaPositivePositive() { 76 testRegularizedGamma(0.632121, 1.0, 1.0); 77 } 78 79 public void testLogGammaNan() { 80 testLogGamma(Double.NaN, Double.NaN); 81 } 82 83 public void testLogGammaNegative() { 84 testLogGamma(Double.NaN, -1.0); 85 } 86 87 public void testLogGammaZero() { 88 testLogGamma(Double.NaN, 0.0); 89 } 90 91 public void testLogGammaPositive() { 92 testLogGamma(0.693147, 3.0); 93 } 94 } 95 | Popular Tags |