1 package JSci.tests; 2 3 import JSci.GlobalSettings; 4 import JSci.maths.Complex; 5 import JSci.maths.ExtraMath; 6 import junit.framework.*; 7 8 12 public class ComplexTest extends junitx.extensions.EqualsHashCodeTestCase { 13 private double x, y; 14 private double u, v; 15 16 public static void main(String arg[]) { 17 junit.textui.TestRunner.run(suite()); 18 } 19 public static Test suite() { 20 return new junit.extensions.RepeatedTest(new TestSuite(ComplexTest.class), 5); 21 } 22 public ComplexTest(String name) { 23 super(name); 24 } 25 protected void setUp() throws Exception { 26 GlobalSettings.ZERO_TOL=1.0e-9; 27 x = ExtraMath.random(-1.0, 1.0); 28 y = ExtraMath.random(-1.0, 1.0); 29 u = ExtraMath.random(-1.0, 1.0); 30 v = ExtraMath.random(-1.0, 1.0); 31 super.setUp(); 32 } 33 protected Object createInstance() { 34 return new Complex(x, y); 35 } 36 protected Object createNotEqualInstance() { 37 return new Complex(u, v); 38 } 39 public void testParseString() { 40 Complex expected = (Complex) createInstance(); 41 Complex actual = new Complex(expected.toString()); 42 assertEquals(expected, actual); 43 expected = new Complex(0.0, Double.MAX_VALUE); 44 actual = new Complex(expected.toString()); 45 assertEquals(expected, actual); 46 expected = new Complex(Double.MIN_VALUE, 0.0); 47 actual = new Complex(expected.toString()); 48 assertEquals(expected, actual); 49 } 50 public void testZero() { 51 assertTrue("0 is zero", Complex.ZERO.isZero()); 52 Complex delta = (Complex) createInstance(); 53 delta = delta.multiply(Math.random()*GlobalSettings.ZERO_TOL/delta.mod()); 54 assertTrue("delta is zero", delta.isZero()); 55 assertTrue("delta == zero", delta.equals(Complex.ZERO)); 56 Complex z = (Complex) createNotEqualInstance(); 57 assertTrue("z == z + delta", z.equals(z.add(delta))); 58 } 59 public void testSin() { 60 Complex expected = (Complex) createInstance(); 61 Complex actual=Complex.sin(Complex.asin(expected)); 62 assertEquals(expected, actual); 63 } 64 public void testCos() { 65 Complex expected = (Complex) createInstance(); 66 Complex actual=Complex.cos(Complex.acos(expected)); 67 assertEquals(expected, actual); 68 } 69 public void testTan() { 70 Complex expected = (Complex) createInstance(); 71 Complex actual=Complex.tan(Complex.atan(expected)); 72 assertEquals(expected, actual); 73 } 74 public void testSinh() { 75 Complex expected = (Complex) createInstance(); 76 Complex actual=Complex.sinh(Complex.asinh(expected)); 77 assertEquals(expected, actual); 78 } 79 public void testCosh() { 80 Complex expected = (Complex) createInstance(); 81 Complex actual=Complex.cosh(Complex.acosh(expected)); 82 assertEquals(expected, actual); 83 } 84 public void testTanh() { 85 Complex expected = (Complex) createInstance(); 86 Complex actual=Complex.tanh(Complex.atanh(expected)); 87 assertEquals(expected, actual); 88 } 89 } 90 91 | Popular Tags |