1 package JSci.tests; 2 3 import JSci.GlobalSettings; 4 import JSci.maths.*; 5 6 10 public class ExtraMathTest extends junit.framework.TestCase { 11 public static void main(String arg[]) { 12 junit.textui.TestRunner.run(ExtraMathTest.class); 13 } 14 public ExtraMathTest(String name) { 15 super(name); 16 } 17 protected void setUp() { 18 GlobalSettings.ZERO_TOL=1.0e-9; 19 } 20 private void assertIdentical(double exp, double actual) { 21 assertEquals(new Double (exp), new Double (actual)); 22 } 23 public void testAsinh() { 24 assertIdentical(-0.0, ExtraMath.asinh(-0.0)); 25 assertIdentical(Double.NEGATIVE_INFINITY, ExtraMath.asinh(Double.NEGATIVE_INFINITY)); 26 double x = Math.random(); 27 assertEquals(x, ExtraMath.asinh(ExtraMath.sinh(x)), GlobalSettings.ZERO_TOL); 28 } 29 public void testAcosh() { 30 double x = Math.random(); 31 assertEquals(x, ExtraMath.acosh(ExtraMath.cosh(x)), GlobalSettings.ZERO_TOL); 32 } 33 public void testAtanh() { 34 assertIdentical(-0.0, ExtraMath.atanh(-0.0)); 35 double x = Math.random(); 36 assertEquals(x, ExtraMath.atanh(ExtraMath.tanh(x)), GlobalSettings.ZERO_TOL); 37 } 38 public void testAcsch() { 39 double x = Math.random(); 40 assertEquals(x, ExtraMath.acsch(ExtraMath.csch(x)), GlobalSettings.ZERO_TOL); 41 } 42 public void testAsech() { 43 double x = Math.random(); 44 assertEquals(x, ExtraMath.asech(ExtraMath.sech(x)), GlobalSettings.ZERO_TOL); 45 } 46 public void testAcoth() { 47 double x = Math.random(); 48 assertEquals(x, ExtraMath.acoth(ExtraMath.coth(x)), GlobalSettings.ZERO_TOL); 49 } 50 public void testRound() { 51 assertEquals(0.0035, ExtraMath.round(0.00345238, 2), 0.0); 53 assertEquals(-0.0000345, ExtraMath.round(-0.0000345238, 3), 0.0); 55 assertEquals(1900.0, ExtraMath.round(1900.0001, 3), 0.0); 57 assertEquals(-3400000.0, ExtraMath.round(-3450000.0, 2), 0.0); 59 } 60 } 61 | Popular Tags |