39 |
|
static final int NCALLS = 10000; |
40 |
|
|
41 |
|
// max sampled int bound |
42 |
< |
static final int MAX_INT_BOUND = (1 << 28); |
42 |
> |
static final int MAX_INT_BOUND = (1 << 26); |
43 |
|
|
44 |
|
// max sampled long bound |
45 |
< |
static final long MAX_LONG_BOUND = (1L << 42); |
45 |
> |
static final long MAX_LONG_BOUND = (1L << 40); |
46 |
|
|
47 |
|
// Number of replications for other checks |
48 |
< |
static final int REPS = 20; |
48 |
> |
static final int REPS = |
49 |
> |
Integer.getInteger("SplittableRandomTest.reps", 4); |
50 |
|
|
51 |
|
/** |
52 |
|
* Repeated calls to nextInt produce at least two distinct results |
128 |
|
} |
129 |
|
|
130 |
|
/** |
131 |
< |
* nextInt(negative) throws IllegalArgumentException |
131 |
> |
* nextInt(non-positive) throws IllegalArgumentException |
132 |
|
*/ |
133 |
< |
public void testNextIntBoundedNeg() { |
133 |
> |
public void testNextIntNonPositive() { |
134 |
|
SplittableRandom sr = new SplittableRandom(); |
135 |
< |
try { |
136 |
< |
int f = sr.nextInt(-17); |
137 |
< |
shouldThrow(); |
138 |
< |
} catch (IllegalArgumentException success) {} |
135 |
> |
Runnable[] throwingActions = { |
136 |
> |
() -> sr.nextInt(-17), |
137 |
> |
() -> sr.nextInt(0), |
138 |
> |
() -> sr.nextInt(Integer.MIN_VALUE), |
139 |
> |
}; |
140 |
> |
assertThrows(IllegalArgumentException.class, throwingActions); |
141 |
|
} |
142 |
|
|
143 |
|
/** |
145 |
|
*/ |
146 |
|
public void testNextIntBadBounds() { |
147 |
|
SplittableRandom sr = new SplittableRandom(); |
148 |
< |
try { |
149 |
< |
int f = sr.nextInt(17, 2); |
150 |
< |
shouldThrow(); |
151 |
< |
} catch (IllegalArgumentException success) {} |
148 |
> |
Runnable[] throwingActions = { |
149 |
> |
() -> sr.nextInt(17, 2), |
150 |
> |
() -> sr.nextInt(-42, -42), |
151 |
> |
() -> sr.nextInt(Integer.MAX_VALUE, Integer.MIN_VALUE), |
152 |
> |
}; |
153 |
> |
assertThrows(IllegalArgumentException.class, throwingActions); |
154 |
|
} |
155 |
|
|
156 |
|
/** |
197 |
|
} |
198 |
|
|
199 |
|
/** |
200 |
< |
* nextLong(negative) throws IllegalArgumentException |
200 |
> |
* nextLong(non-positive) throws IllegalArgumentException |
201 |
|
*/ |
202 |
< |
public void testNextLongBoundedNeg() { |
202 |
> |
public void testNextLongNonPositive() { |
203 |
|
SplittableRandom sr = new SplittableRandom(); |
204 |
< |
try { |
205 |
< |
long f = sr.nextLong(-17); |
206 |
< |
shouldThrow(); |
207 |
< |
} catch (IllegalArgumentException success) {} |
204 |
> |
Runnable[] throwingActions = { |
205 |
> |
() -> sr.nextLong(-17L), |
206 |
> |
() -> sr.nextLong(0L), |
207 |
> |
() -> sr.nextLong(Long.MIN_VALUE), |
208 |
> |
}; |
209 |
> |
assertThrows(IllegalArgumentException.class, throwingActions); |
210 |
|
} |
211 |
|
|
212 |
|
/** |
214 |
|
*/ |
215 |
|
public void testNextLongBadBounds() { |
216 |
|
SplittableRandom sr = new SplittableRandom(); |
217 |
< |
try { |
218 |
< |
long f = sr.nextLong(17, 2); |
219 |
< |
shouldThrow(); |
220 |
< |
} catch (IllegalArgumentException success) {} |
217 |
> |
Runnable[] throwingActions = { |
218 |
> |
() -> sr.nextLong(17L, 2L), |
219 |
> |
() -> sr.nextLong(-42L, -42L), |
220 |
> |
() -> sr.nextLong(Long.MAX_VALUE, Long.MIN_VALUE), |
221 |
> |
}; |
222 |
> |
assertThrows(IllegalArgumentException.class, throwingActions); |
223 |
|
} |
224 |
|
|
225 |
|
/** |
265 |
|
} |
266 |
|
|
267 |
|
/** |
268 |
+ |
* nextDouble(non-positive) throws IllegalArgumentException |
269 |
+ |
*/ |
270 |
+ |
public void testNextDoubleNonPositive() { |
271 |
+ |
SplittableRandom sr = new SplittableRandom(); |
272 |
+ |
Runnable[] throwingActions = { |
273 |
+ |
() -> sr.nextDouble(-17.0d), |
274 |
+ |
() -> sr.nextDouble(0.0d), |
275 |
+ |
() -> sr.nextDouble(-Double.MIN_VALUE), |
276 |
+ |
() -> sr.nextDouble(Double.NEGATIVE_INFINITY), |
277 |
+ |
() -> sr.nextDouble(Double.NaN), |
278 |
+ |
}; |
279 |
+ |
assertThrows(IllegalArgumentException.class, throwingActions); |
280 |
+ |
} |
281 |
+ |
|
282 |
+ |
/** |
283 |
+ |
* nextDouble(! (least < bound)) throws IllegalArgumentException |
284 |
+ |
*/ |
285 |
+ |
public void testNextDoubleBadBounds() { |
286 |
+ |
SplittableRandom sr = new SplittableRandom(); |
287 |
+ |
Runnable[] throwingActions = { |
288 |
+ |
() -> sr.nextDouble(17.0d, 2.0d), |
289 |
+ |
() -> sr.nextDouble(-42.0d, -42.0d), |
290 |
+ |
() -> sr.nextDouble(Double.MAX_VALUE, Double.MIN_VALUE), |
291 |
+ |
() -> sr.nextDouble(Double.NaN, 0.0d), |
292 |
+ |
() -> sr.nextDouble(0.0d, Double.NaN), |
293 |
+ |
}; |
294 |
+ |
assertThrows(IllegalArgumentException.class, throwingActions); |
295 |
+ |
} |
296 |
+ |
|
297 |
+ |
// TODO: Test infinite bounds! |
298 |
+ |
//() -> sr.nextDouble(Double.NEGATIVE_INFINITY, 0.0d), |
299 |
+ |
//() -> sr.nextDouble(0.0d, Double.POSITIVE_INFINITY), |
300 |
+ |
|
301 |
+ |
/** |
302 |
|
* nextDouble(least, bound) returns least <= value < bound; |
303 |
|
* repeated calls produce at least two distinct results |
304 |
|
*/ |
326 |
|
*/ |
327 |
|
public void testBadStreamSize() { |
328 |
|
SplittableRandom r = new SplittableRandom(); |
329 |
< |
try { |
330 |
< |
java.util.stream.IntStream x = r.ints(-1L); |
331 |
< |
shouldThrow(); |
332 |
< |
} catch (IllegalArgumentException success) {} |
333 |
< |
try { |
334 |
< |
java.util.stream.IntStream x = r.ints(-1L, 2, 3); |
335 |
< |
shouldThrow(); |
336 |
< |
} catch (IllegalArgumentException success) {} |
337 |
< |
try { |
295 |
< |
java.util.stream.LongStream x = r.longs(-1L); |
296 |
< |
shouldThrow(); |
297 |
< |
} catch (IllegalArgumentException success) {} |
298 |
< |
try { |
299 |
< |
java.util.stream.LongStream x = r.longs(-1L, -1L, 1L); |
300 |
< |
shouldThrow(); |
301 |
< |
} catch (IllegalArgumentException success) {} |
302 |
< |
try { |
303 |
< |
java.util.stream.DoubleStream x = r.doubles(-1L); |
304 |
< |
shouldThrow(); |
305 |
< |
} catch (IllegalArgumentException success) {} |
306 |
< |
try { |
307 |
< |
java.util.stream.DoubleStream x = r.doubles(-1L, .5, .6); |
308 |
< |
shouldThrow(); |
309 |
< |
} catch (IllegalArgumentException success) {} |
329 |
> |
Runnable[] throwingActions = { |
330 |
> |
() -> { java.util.stream.IntStream x = r.ints(-1L); }, |
331 |
> |
() -> { java.util.stream.IntStream x = r.ints(-1L, 2, 3); }, |
332 |
> |
() -> { java.util.stream.LongStream x = r.longs(-1L); }, |
333 |
> |
() -> { java.util.stream.LongStream x = r.longs(-1L, -1L, 1L); }, |
334 |
> |
() -> { java.util.stream.DoubleStream x = r.doubles(-1L); }, |
335 |
> |
() -> { java.util.stream.DoubleStream x = r.doubles(-1L, .5, .6); }, |
336 |
> |
}; |
337 |
> |
assertThrows(IllegalArgumentException.class, throwingActions); |
338 |
|
} |
339 |
|
|
340 |
|
/** |
343 |
|
*/ |
344 |
|
public void testBadStreamBounds() { |
345 |
|
SplittableRandom r = new SplittableRandom(); |
346 |
< |
try { |
347 |
< |
java.util.stream.IntStream x = r.ints(2, 1); |
348 |
< |
shouldThrow(); |
349 |
< |
} catch (IllegalArgumentException success) {} |
350 |
< |
try { |
351 |
< |
java.util.stream.IntStream x = r.ints(10, 42, 42); |
352 |
< |
shouldThrow(); |
353 |
< |
} catch (IllegalArgumentException success) {} |
354 |
< |
try { |
327 |
< |
java.util.stream.LongStream x = r.longs(-1L, -1L); |
328 |
< |
shouldThrow(); |
329 |
< |
} catch (IllegalArgumentException success) {} |
330 |
< |
try { |
331 |
< |
java.util.stream.LongStream x = r.longs(10, 1L, -2L); |
332 |
< |
shouldThrow(); |
333 |
< |
} catch (IllegalArgumentException success) {} |
334 |
< |
try { |
335 |
< |
java.util.stream.DoubleStream x = r.doubles(0.0, 0.0); |
336 |
< |
shouldThrow(); |
337 |
< |
} catch (IllegalArgumentException success) {} |
338 |
< |
try { |
339 |
< |
java.util.stream.DoubleStream x = r.doubles(10, .5, .4); |
340 |
< |
shouldThrow(); |
341 |
< |
} catch (IllegalArgumentException success) {} |
346 |
> |
Runnable[] throwingActions = { |
347 |
> |
() -> { java.util.stream.IntStream x = r.ints(2, 1); }, |
348 |
> |
() -> { java.util.stream.IntStream x = r.ints(10, 42, 42); }, |
349 |
> |
() -> { java.util.stream.LongStream x = r.longs(-1L, -1L); }, |
350 |
> |
() -> { java.util.stream.LongStream x = r.longs(10, 1L, -2L); }, |
351 |
> |
() -> { java.util.stream.DoubleStream x = r.doubles(0.0, 0.0); }, |
352 |
> |
() -> { java.util.stream.DoubleStream x = r.doubles(10, .5, .4); }, |
353 |
> |
}; |
354 |
> |
assertThrows(IllegalArgumentException.class, throwingActions); |
355 |
|
} |
356 |
|
|
357 |
|
/** |