01: package JSci.tests;
02:
03: import JSci.GlobalSettings;
04: import JSci.maths.*;
05:
06: /**
07: * Testcase for extra math methods.
08: * @author Mark Hale
09: */
10: public class ExtraMathTest extends junit.framework.TestCase {
11: public static void main(String arg[]) {
12: junit.textui.TestRunner.run(ExtraMathTest.class);
13: }
14:
15: public ExtraMathTest(String name) {
16: super (name);
17: }
18:
19: protected void setUp() {
20: GlobalSettings.ZERO_TOL = 1.0e-9;
21: }
22:
23: private void assertIdentical(double exp, double actual) {
24: assertEquals(new Double(exp), new Double(actual));
25: }
26:
27: public void testAsinh() {
28: assertIdentical(-0.0, ExtraMath.asinh(-0.0));
29: assertIdentical(Double.NEGATIVE_INFINITY, ExtraMath
30: .asinh(Double.NEGATIVE_INFINITY));
31: double x = Math.random();
32: assertEquals(x, ExtraMath.asinh(ExtraMath.sinh(x)),
33: GlobalSettings.ZERO_TOL);
34: }
35:
36: public void testAcosh() {
37: double x = Math.random();
38: assertEquals(x, ExtraMath.acosh(ExtraMath.cosh(x)),
39: GlobalSettings.ZERO_TOL);
40: }
41:
42: public void testAtanh() {
43: assertIdentical(-0.0, ExtraMath.atanh(-0.0));
44: double x = Math.random();
45: assertEquals(x, ExtraMath.atanh(ExtraMath.tanh(x)),
46: GlobalSettings.ZERO_TOL);
47: }
48:
49: public void testAcsch() {
50: double x = Math.random();
51: assertEquals(x, ExtraMath.acsch(ExtraMath.csch(x)),
52: GlobalSettings.ZERO_TOL);
53: }
54:
55: public void testAsech() {
56: double x = Math.random();
57: assertEquals(x, ExtraMath.asech(ExtraMath.sech(x)),
58: GlobalSettings.ZERO_TOL);
59: }
60:
61: public void testAcoth() {
62: double x = Math.random();
63: assertEquals(x, ExtraMath.acoth(ExtraMath.coth(x)),
64: GlobalSettings.ZERO_TOL);
65: }
66:
67: public void testRound() {
68: // +ve value, -ve exp, round-up
69: assertEquals(0.0035, ExtraMath.round(0.00345238, 2), 0.0);
70: // -ve value, -ve exp, round-down
71: assertEquals(-0.0000345, ExtraMath.round(-0.0000345238, 3), 0.0);
72: // +ve value, +ve exp, round-down
73: assertEquals(1900.0, ExtraMath.round(1900.0001, 3), 0.0);
74: // -ve value, +ve exp, round-up
75: assertEquals(-3400000.0, ExtraMath.round(-3450000.0, 2), 0.0);
76: }
77: }
|