KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > tests > SpecialTest


1 package JSci.tests;
2
3 import JSci.maths.*;
4
5 /**
6 * Testcase for special function methods.
7 * @author Mark Hale
8 */

9 public class SpecialTest extends junit.framework.TestCase {
10         public static void main(String JavaDoc arg[]) {
11                 junit.textui.TestRunner.run(SpecialTest.class);
12         }
13         public SpecialTest(String JavaDoc name) {
14                 super(name);
15         }
16         /**
17         * Tests the gamma function against its functional equation.
18         */

19         public void testGammaFunctional() {
20                 for(int i=0; i<10; i++) {
21                         double x = SpecialMath.GAMMA_X_MAX_VALUE*Math.random();
22                         double expected = x*SpecialMath.gamma(x);
23                         double ans = SpecialMath.gamma(x+1.0);
24                         assertEquals(expected, ans, 1.0e-10*Math.abs(expected));
25                 }
26         }
27         /**
28         * Tests the gamma function against the Legendre duplication formula.
29         */

30         public void testGammaDuplication() {
31                 for(int i=0; i<10; i++) {
32                         double x = Math.sqrt(SpecialMath.GAMMA_X_MAX_VALUE)*Math.random();
33                         double expected = Math.pow(4.0, x)/(2.0*Math.sqrt(Math.PI))*SpecialMath.gamma(x)*SpecialMath.gamma(x+0.5);
34                         double ans = SpecialMath.gamma(2.0*x);
35                         assertEquals(expected, ans, 1.0e-10*Math.abs(expected));
36                 }
37         }
38 }
39
40
Popular Tags