package JSci.tests;

import JSci.maths.Complex;

/**
* Testcase for complex numbers.
* @author Mark Hale
*/
public class ComplexTest extends junitx.extensions.EqualsHashCodeTestCase {
        private double x, y;
        private double u, v;

        public static void main(String arg[]) {
                junit.textui.TestRunner.run(ComplexTest.class);
        }
        public ComplexTest(String name) {
                super(name);
        }
        protected void setUp() throws Exception {
                JSci.GlobalSettings.ZERO_TOL=1.0e-10;
                x = Math.random();
                y = Math.random();
                u = Math.random();
                v = Math.random();
                super.setUp();
        }
        protected Object createInstance() {
                return new Complex(x, y);
        }
        protected Object createNotEqualInstance() {
                return new Complex(u, v);
        }
        public void testParseString() {
                Complex expected = (Complex) createInstance();
                Complex actual = new Complex(expected.toString());
                assertEquals(expected, actual);
                expected = new Complex(0.0, Double.MAX_VALUE);
                actual = new Complex(expected.toString());
                assertEquals(expected, actual);
                expected = new Complex(Double.MIN_VALUE, 0.0);
                actual = new Complex(expected.toString());
                assertEquals(expected, actual);
        }
        public void testSin() {
                Complex expected = (Complex) createInstance();
                Complex actual=Complex.sin(Complex.asin(expected));
                assertEquals(expected, actual);
        }
        public void testCos() {
                Complex expected = (Complex) createInstance();
                Complex actual=Complex.cos(Complex.acos(expected));
                assertEquals(expected, actual);
        }
        public void testTan() {
                Complex expected = (Complex) createInstance();
                Complex actual=Complex.tan(Complex.atan(expected));
                assertEquals(expected, actual);
        }
        public void testSinh() {
                Complex expected = (Complex) createInstance();
                Complex actual=Complex.sinh(Complex.asinh(expected));
                assertEquals(expected, actual);
        }
        public void testCosh() {
                Complex expected = (Complex) createInstance();
                Complex actual=Complex.cosh(Complex.acosh(expected));
                assertEquals(expected, actual);
        }
        public void testTanh() {
                Complex expected = (Complex) createInstance();
                Complex actual=Complex.tanh(Complex.atanh(expected));
                assertEquals(expected, actual);
        }
}

