01: package JSci.tests;
02:
03: import JSci.maths.*;
04:
05: /**
06: * Testcase for special function methods.
07: * @author Mark Hale
08: */
09: public class SpecialTest extends junit.framework.TestCase {
10: public static void main(String arg[]) {
11: junit.textui.TestRunner.run(SpecialTest.class);
12: }
13:
14: public SpecialTest(String name) {
15: super (name);
16: }
17:
18: /**
19: * Tests the gamma function against its functional equation.
20: */
21: public void testGammaFunctional() {
22: for (int i = 0; i < 10; i++) {
23: double x = SpecialMath.GAMMA_X_MAX_VALUE * Math.random();
24: double expected = x * SpecialMath.gamma(x);
25: double ans = SpecialMath.gamma(x + 1.0);
26: assertEquals(expected, ans, 1.0e-10 * Math.abs(expected));
27: }
28: }
29:
30: /**
31: * Tests the gamma function against the Legendre duplication formula.
32: */
33: public void testGammaDuplication() {
34: for (int i = 0; i < 10; i++) {
35: double x = Math.sqrt(SpecialMath.GAMMA_X_MAX_VALUE)
36: * Math.random();
37: double expected = Math.pow(4.0, x)
38: / (2.0 * Math.sqrt(Math.PI)) * SpecialMath.gamma(x)
39: * SpecialMath.gamma(x + 0.5);
40: double ans = SpecialMath.gamma(2.0 * x);
41: assertEquals(expected, ans, 1.0e-10 * Math.abs(expected));
42: }
43: }
44: }
|