1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.rng.core.source64;
18
19 import org.junit.Assert;
20 import org.junit.Test;
21
22
23 public class TwoCmresTest {
24 @Test
25 public void testAsymmetric() {
26 final int index1 = 2;
27 final int index2 = 5;
28 final int seed = -123456789;
29
30 final TwoCmres rng1 = new TwoCmres(seed, index1, index2);
31 final TwoCmres rng2 = new TwoCmres(seed, index2, index1);
32
33
34 final int n = 1000;
35 for (int i = 0; i < n; i++) {
36 Assert.assertNotEquals("i=" + i, rng1.nextLong(), rng2.nextLong());
37 }
38 }
39
40 @Test
41 public void testSubcycleGeneratorsMustBeDifferent() {
42 final int max = TwoCmres.numberOfSubcycleGenerators();
43 for (int i = 0; i < max; i++) {
44 try {
45 new TwoCmres(-97845, i, i);
46 Assert.fail("Exception expected");
47 } catch (IllegalArgumentException e) {
48
49 }
50 }
51 }
52
53 @Test
54 public void testSubcycleGeneratorsIndex() {
55 final int seed = 246810;
56
57
58 final int max = TwoCmres.numberOfSubcycleGenerators();
59
60 for (int i = 0; i < max; i++) {
61 for (int j = 0; j < max; j++) {
62 if (i != j) {
63
64 new TwoCmres(seed, i, j);
65 }
66 }
67 }
68
69 for (int wrongIndex : new int[] { -1, max }) {
70 try {
71 new TwoCmres(seed, wrongIndex, 1);
72 Assert.fail("Exception expected for index=" + wrongIndex);
73 } catch (IndexOutOfBoundsException e) {
74
75 }
76
77 try {
78 new TwoCmres(seed, 1, wrongIndex);
79 Assert.fail("Exception expected for index=" + wrongIndex);
80 } catch (IndexOutOfBoundsException e) {
81
82 }
83 }
84 }
85 }