50 |
|
Integer.getInteger("SplittableRandomTest.reps", 4); |
51 |
|
|
52 |
|
/** |
53 |
+ |
* Repeated calls to next (only accessible via reflection) produce |
54 |
+ |
* at least two distinct results, and repeated calls produce all |
55 |
+ |
* possible values. |
56 |
+ |
*/ |
57 |
+ |
public void testNext() throws ReflectiveOperationException { |
58 |
+ |
SplittableRandom rnd = new SplittableRandom(); |
59 |
+ |
try { |
60 |
+ |
java.lang.reflect.Method m |
61 |
+ |
= SplittableRandom.class.getDeclaredMethod( |
62 |
+ |
"next", new Class[] { int.class }); |
63 |
+ |
m.setAccessible(true); |
64 |
+ |
|
65 |
+ |
int i; |
66 |
+ |
{ |
67 |
+ |
int val = new java.util.Random().nextInt(4); |
68 |
+ |
for (i = 0; i < NCALLS; i++) { |
69 |
+ |
int q = (int) m.invoke(rnd, new Object[] { 2 }); |
70 |
+ |
if (val == q) break; |
71 |
+ |
} |
72 |
+ |
assertTrue(i < NCALLS); |
73 |
+ |
} |
74 |
+ |
|
75 |
+ |
{ |
76 |
+ |
int r = (int) m.invoke(rnd, new Object[] { 3 }); |
77 |
+ |
for (i = 0; i < NCALLS; i++) { |
78 |
+ |
int q = (int) m.invoke(rnd, new Object[] { 3 }); |
79 |
+ |
assertTrue(q < (1<<3)); |
80 |
+ |
if (r != q) break; |
81 |
+ |
} |
82 |
+ |
assertTrue(i < NCALLS); |
83 |
+ |
} |
84 |
+ |
} catch (SecurityException acceptable) {} |
85 |
+ |
} |
86 |
+ |
|
87 |
+ |
/** |
88 |
|
* Repeated calls to nextInt produce at least two distinct results |
89 |
|
*/ |
90 |
|
public void testNextInt() { |
195 |
|
*/ |
196 |
|
public void testNextIntBounded() { |
197 |
|
SplittableRandom sr = new SplittableRandom(); |
198 |
+ |
for (int i = 0; i < 2; i++) assertEquals(0, sr.nextInt(1)); |
199 |
|
// sample bound space across prime number increments |
200 |
|
for (int bound = 2; bound < MAX_INT_BOUND; bound += 524959) { |
201 |
|
int f = sr.nextInt(bound); |
265 |
|
*/ |
266 |
|
public void testNextLongBounded() { |
267 |
|
SplittableRandom sr = new SplittableRandom(); |
268 |
+ |
for (int i = 0; i < 2; i++) assertEquals(0L, sr.nextLong(1L)); |
269 |
|
for (long bound = 2; bound < MAX_LONG_BOUND; bound += 15485863) { |
270 |
|
long f = sr.nextLong(bound); |
271 |
|
assertTrue(0 <= f && f < bound); |