01: /*
02: * Copyright 2003-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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: /**
24: * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
25: */
26: public class GammaTest extends TestCase {
27: /**
28: * Constructor for BetaTest.
29: * @param name
30: */
31: public GammaTest(String name) {
32: super (name);
33: }
34:
35: private void testRegularizedGamma(double expected, double a,
36: double x) {
37: try {
38: double actualP = Gamma.regularizedGammaP(a, x);
39: double actualQ = Gamma.regularizedGammaQ(a, x);
40: TestUtils.assertEquals(expected, actualP, 10e-5);
41: TestUtils.assertEquals(actualP, 1.0 - actualQ, 10e-5);
42: } catch (MathException ex) {
43: fail(ex.getMessage());
44: }
45: }
46:
47: private void testLogGamma(double expected, double x) {
48: double actual = Gamma.logGamma(x);
49: TestUtils.assertEquals(expected, actual, 10e-5);
50: }
51:
52: public void testRegularizedGammaNanPositive() {
53: testRegularizedGamma(Double.NaN, Double.NaN, 1.0);
54: }
55:
56: public void testRegularizedGammaPositiveNan() {
57: testRegularizedGamma(Double.NaN, 1.0, Double.NaN);
58: }
59:
60: public void testRegularizedGammaNegativePositive() {
61: testRegularizedGamma(Double.NaN, -1.5, 1.0);
62: }
63:
64: public void testRegularizedGammaPositiveNegative() {
65: testRegularizedGamma(Double.NaN, 1.0, -1.0);
66: }
67:
68: public void testRegularizedGammaZeroPositive() {
69: testRegularizedGamma(Double.NaN, 0.0, 1.0);
70: }
71:
72: public void testRegularizedGammaPositiveZero() {
73: testRegularizedGamma(0.0, 1.0, 0.0);
74: }
75:
76: public void testRegularizedGammaPositivePositive() {
77: testRegularizedGamma(0.632121, 1.0, 1.0);
78: }
79:
80: public void testLogGammaNan() {
81: testLogGamma(Double.NaN, Double.NaN);
82: }
83:
84: public void testLogGammaNegative() {
85: testLogGamma(Double.NaN, -1.0);
86: }
87:
88: public void testLogGammaZero() {
89: testLogGamma(Double.NaN, 0.0);
90: }
91:
92: public void testLogGammaPositive() {
93: testLogGamma(0.693147, 3.0);
94: }
95: }
|