01: package JSci.tests;
02:
03: import java.util.Map;
04: import java.util.HashMap;
05: import junit.framework.*;
06: import JSci.maths.statistics.*;
07:
08: /**
09: * Testcase for statistical distributions.
10: * @author Mark Hale
11: */
12: public class StatisticsTest extends junit.framework.TestCase {
13: private ProbabilityDistribution distribution;
14:
15: public static void main(String arg[]) {
16: junit.textui.TestRunner.run(suite());
17: }
18:
19: public static Test suite() {
20: ProbabilityDistribution[] distrs = new ProbabilityDistribution[] {
21: new NormalDistribution(), new CauchyDistribution(),
22: new BetaDistribution(5, 13), new FDistribution(5, 13),
23: new TDistribution(11), new GeometricDistribution(0.3),
24: new GammaDistribution(1.5),
25: new ExponentialDistribution(),
26: new LognormalDistribution(),
27: new WeibullDistribution(1.5) };
28: TestSuite suite = new TestSuite(StatisticsTest.class.toString());
29: for (int i = 0; i < distrs.length; i++) {
30: Map properties = new HashMap();
31: properties.put("test.statistics.distribution", distrs[i]);
32: suite.addTest(new TestProperties(new TestSuite(
33: StatisticsTest.class, distrs[i].toString()),
34: properties));
35: }
36: return suite;
37: }
38:
39: public StatisticsTest(String name) {
40: super (name);
41: }
42:
43: protected void setUp() {
44: JSci.GlobalSettings.ZERO_TOL = 1.0e-8;
45: distribution = (ProbabilityDistribution) TestProperties
46: .getProperties().get("test.statistics.distribution");
47: }
48:
49: /**
50: * Test inverse of cumulative distribution function.
51: */
52: public void testInverse() {
53: double expected = Math.random();
54: double actual = distribution.inverse(distribution
55: .cumulative(expected));
56: assertEquals(expected, actual, JSci.GlobalSettings.ZERO_TOL);
57: }
58: }
|