KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > tests > StatisticsTest


1 package JSci.tests;
2
3 import java.util.Map JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import junit.framework.*;
6 import JSci.maths.statistics.*;
7
8 /**
9 * 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 JavaDoc arg[]) {
16                 junit.textui.TestRunner.run(suite());
17         }
18         public static Test suite() {
19                 ProbabilityDistribution[] distrs = new ProbabilityDistribution[] {
20                         new NormalDistribution(),
21                         new CauchyDistribution(),
22                         new BetaDistribution(5, 13),
23                         new FDistribution(5, 13),
24                         new TDistribution(11),
25                         new GeometricDistribution(0.3),
26                         new GammaDistribution(1.5),
27                         new ExponentialDistribution(),
28                         new LognormalDistribution(),
29                         new WeibullDistribution(1.5)
30                 };
31                 TestSuite suite = new TestSuite(StatisticsTest.class.toString());
32                 for(int i=0; i<distrs.length; i++) {
33                         Map JavaDoc properties = new HashMap JavaDoc();
34                         properties.put("test.statistics.distribution", distrs[i]);
35                         suite.addTest(new TestProperties(new TestSuite(StatisticsTest.class, distrs[i].toString()), properties));
36                 }
37                 return suite;
38         }
39         public StatisticsTest(String JavaDoc name) {
40                 super(name);
41         }
42         protected void setUp() {
43                 JSci.GlobalSettings.ZERO_TOL=1.0e-8;
44                 distribution = (ProbabilityDistribution) TestProperties.getProperties().get("test.statistics.distribution");
45         }
46         /**
47         * Test inverse of cumulative distribution function.
48         */

49         public void testInverse() {
50                 double expected = Math.random();
51                 double actual = distribution.inverse(distribution.cumulative(expected));
52                 assertEquals(expected, actual, JSci.GlobalSettings.ZERO_TOL);
53         }
54 }
55
56
Popular Tags