01 /*
02 * Created on Sep 14, 2007
03 *
04 */
05 package com.x8ing.mc;
06
07 import junit.framework.TestCase;
08
09 import com.x8ing.mc.distribution.RandomDistribution;
10 import com.x8ing.mc.distribution.RandomDistributionConstant;
11 import com.x8ing.mc.distribution.RandomDistributionGauss;
12
13 /**
14 * @author Patrick Heusser
15 */
16 public class DistributedRandomFactoryTest extends TestCase {
17
18 public static final int LOOPS = 1000;
19
20 public void testConstant1() {
21
22 // check interval (heuristic test)
23 int rangeMin = 0;
24 int rangeMax = 100;
25 RandomDistribution rnd = new RandomDistributionConstant(rangeMin, rangeMax);
26 implTest(rangeMin, rangeMax, rnd);
27
28 }
29
30 public void testConstant2() {
31
32 // check interval (heuristic test)
33 int rangeMin = -100;
34 int rangeMax = -50;
35 RandomDistribution rnd = new RandomDistributionConstant(rangeMin, rangeMax);
36 implTest(rangeMin, rangeMax, rnd);
37
38 }
39
40 public void testGauss1() {
41
42 // check interval (heuristic test)
43 int rangeMin = 100;
44 int rangeMax = 300;
45 RandomDistribution rnd = new RandomDistributionGauss(rangeMin, rangeMax, 1);
46
47 final int LOOPS = 100000;
48 double[] d = new double[LOOPS];
49
50 for (int i = 0; i < d.length; i++) {
51 d[i] = rnd.getNextRandomNumber();
52 }
53
54 implTest(rangeMin, rangeMax, rnd);
55
56 Statistic statistic = new Statistic(d);
57 System.out.println(statistic.getDistributionPrint(100));
58
59 }
60
61 private void implTest(int rangeMin, int rangeMax, RandomDistribution rnd) {
62
63 for (int i = 0; i < LOOPS; i++) {
64
65 double r = rnd.getNextRandomNumber();
66
67 assertTrue(r <= rangeMax);
68 assertTrue(r >= rangeMin);
69
70 }
71 }
72
73 }
|