1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.rng.simple;
19
20 import java.util.Arrays;
21 import org.junit.Assert;
22
23 import org.apache.commons.rng.UniformRandomProvider;
24
25 public final class RandomAssert {
26
27
28
29 private RandomAssert() {}
30
31
32
33
34
35
36
37
38 public static void assertProduceSameSequence(UniformRandomProvider rng1,
39 UniformRandomProvider rng2) {
40 for (int i = 0; i < 54; i++) {
41 Assert.assertTrue(rng1.nextBoolean() == rng2.nextBoolean());
42 }
43 for (int i = 0; i < 23; i++) {
44 Assert.assertEquals(rng1.nextInt(), rng2.nextInt());
45 }
46 for (int i = 0; i < 4; i++) {
47 for (int j = 0; j < 5; j++) {
48 final int max = 107 * i + 374 * j + 11;
49 Assert.assertEquals(rng1.nextInt(max), rng2.nextInt(max));
50 }
51 }
52 for (int i = 0; i < 23; i++) {
53 Assert.assertEquals(rng1.nextLong(), rng2.nextLong());
54 }
55 for (int i = 0; i < 4; i++) {
56 for (int j = 0; j < 5; j++) {
57 final long max = (Long.MAX_VALUE << 2) + 107 * i + 374 * j + 11;
58 Assert.assertEquals(rng1.nextLong(max), rng2.nextLong(max));
59 }
60 }
61 for (int i = 0; i < 103; i++) {
62 Assert.assertEquals(rng1.nextFloat(), rng2.nextFloat(), 0);
63 }
64 for (int i = 0; i < 79; i++) {
65 Assert.assertEquals(rng1.nextDouble(), rng2.nextDouble(), 0);
66 }
67
68 final int size = 345;
69 final byte[] a1 = new byte[size];
70 final byte[] a2 = new byte[size];
71
72 for (int i = 0; i < 3; i++) {
73 rng1.nextBytes(a1);
74 rng2.nextBytes(a2);
75 Assert.assertTrue(Arrays.equals(a1, a2));
76 }
77
78 for (int i = 0; i < 5; i++) {
79 final int offset = 200 + i;
80 final int n = 23 + i;
81 rng1.nextBytes(a1, offset, n);
82 rng2.nextBytes(a2, offset, n);
83 Assert.assertTrue(Arrays.equals(a1, a2));
84 }
85 }
86 }