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 class RandomAssert {
26
27
28
29
30
31
32
33 public static void assertProduceSameSequence(UniformRandomProvider rng1,
34 UniformRandomProvider rng2) {
35 for (int i = 0; i < 54; i++) {
36 Assert.assertTrue(rng1.nextBoolean() == rng2.nextBoolean());
37 }
38 for (int i = 0; i < 23; i++) {
39 Assert.assertEquals(rng1.nextInt(), rng2.nextInt());
40 }
41 for (int i = 0; i < 4; i++) {
42 for (int j = 0; j < 5; j++) {
43 final int max = 107 * i + 374 * j + 11;
44 Assert.assertEquals(rng1.nextInt(max), rng2.nextInt(max));
45 }
46 }
47 for (int i = 0; i < 23; i++) {
48 Assert.assertEquals(rng1.nextLong(), rng2.nextLong());
49 }
50 for (int i = 0; i < 4; i++) {
51 for (int j = 0; j < 5; j++) {
52 final long max = (Long.MAX_VALUE << 2) + 107 * i + 374 * j + 11;
53 Assert.assertEquals(rng1.nextLong(max), rng2.nextLong(max));
54 }
55 }
56 for (int i = 0; i < 103; i++) {
57 Assert.assertEquals(rng1.nextFloat(), rng2.nextFloat(), 0);
58 }
59 for (int i = 0; i < 79; i++) {
60 Assert.assertEquals(rng1.nextDouble(), rng2.nextDouble(), 0);
61 }
62
63 final int size = 345;
64 final byte[] a1 = new byte[size];
65 final byte[] a2 = new byte[size];
66
67 for (int i = 0; i < 3; i++) {
68 rng1.nextBytes(a1);
69 rng2.nextBytes(a2);
70 Assert.assertTrue(Arrays.equals(a1, a2));
71 }
72
73 for (int i = 0; i < 5; i++) {
74 final int offset = 200 + i;
75 final int n = 23 + i;
76 rng1.nextBytes(a1, offset, n);
77 rng2.nextBytes(a2, offset, n);
78 Assert.assertTrue(Arrays.equals(a1, a2));
79 }
80 }
81 }