package JSci.tests;

import junit.framework.*;
import JSci.maths.statistics.*;

/**
* Testcase for statistical distributions.
* @author Mark Hale
*/
public class StatisticsTest extends junit.framework.TestCase {
        private static final ProbabilityDistribution[] distrs = new ProbabilityDistribution[] {
                new NormalDistribution(),
                new CauchyDistribution(),
                new BetaDistribution(5, 13),
                new FDistribution(5, 13),
                new TDistribution(11),
                new GeometricDistribution(0.3),
                new GammaDistribution(1.5),
                new ExponentialDistribution(),
                new LognormalDistribution(),
                new WeibullDistribution(1.5)
        };
        private static int distrsIndex;
        private final ProbabilityDistribution distribution;

        public static void main(String arg[]) {
                junit.textui.TestRunner.run(suite());
        }
        public static Test suite() {
                TestSuite suite = new TestSuite(StatisticsTest.class.toString());
                for(distrsIndex = 0; distrsIndex < distrs.length; distrsIndex++)
                        suite.addTest(new TestSuite(StatisticsTest.class, distrs[distrsIndex].toString()));
                return suite;
        }
        public StatisticsTest(String name) {
                super(name);
                distribution = distrs[distrsIndex];
        }
        protected void setUp() {
                JSci.GlobalSettings.ZERO_TOL=1.0e-8;
        }
        /**
        * Test inverse of cumulative distribution function.
        */
        public void testInverse() {
                double expected = Math.random();
                double actual = distribution.inverse(distribution.cumulative(expected));
                assertEquals(expected, actual, JSci.GlobalSettings.ZERO_TOL);
        }
}

