package JSci.tests;

import JSci.maths.*;

/**
* Testcase for numerical integration methods.
* @author Mark Hale
*/
public class NumericalTest extends junit.framework.TestCase {
        private final Mapping func=new Mapping() {
                public double map(double x) {
                        return 1.0/x;
                }
                public Complex map(Complex z) {
                        return Complex.ONE.divide(z);
                }
        };
        private final double a=1.0;
        private final double b=Math.E;
        private final double expected=1.0;

        public static void main(String arg[]) {
                junit.textui.TestRunner.run(NumericalTest.class);
        }
        public NumericalTest(String name) {
                super(name);
        }
        protected void setUp() {
                JSci.GlobalSettings.ZERO_TOL=1.0e-6;
        }
        public void testTrapezium() {
                double ans=NumericalMath.trapezium(500,func,a,b);
                assertEquals(expected, ans, JSci.GlobalSettings.ZERO_TOL);
        }
        public void testSimpson() {
                double ans=NumericalMath.simpson(20,func,a,b);
                assertEquals(expected, ans, JSci.GlobalSettings.ZERO_TOL);
        }
        public void testRichardson() {
                double ans=NumericalMath.richardson(5,func,a,b);
                assertEquals(expected, ans, JSci.GlobalSettings.ZERO_TOL);
        }
        public void testGaussian4() {
                double ans=NumericalMath.gaussian4(2,func,a,b);
                assertEquals(expected, ans, JSci.GlobalSettings.ZERO_TOL);
        }
        public void testGaussian8() {
                double ans=NumericalMath.gaussian8(1,func,a,b);
                assertEquals(expected, ans, JSci.GlobalSettings.ZERO_TOL);
        }
}

