use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextLongBadBounds.
/**
* nextLong(least >= bound) throws IllegalArgumentException
*/
public void testNextLongBadBounds() {
SplittableRandom sr = new SplittableRandom();
Runnable[] throwingActions = { () -> sr.nextLong(17L, 2L), () -> sr.nextLong(-42L, -42L), () -> sr.nextLong(Long.MAX_VALUE, Long.MIN_VALUE) };
assertThrows(IllegalArgumentException.class, throwingActions);
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testBadStreamBounds.
/**
* Invoking bounded ints, long, doubles, with illegal bounds throws
* IllegalArgumentException
*/
@SuppressWarnings("unused")
public void testBadStreamBounds() {
SplittableRandom r = new SplittableRandom();
Runnable[] throwingActions = { () -> {
java8.util.stream.IntStream x = r.ints(2, 1);
}, () -> {
java8.util.stream.IntStream x = r.ints(10, 42, 42);
}, () -> {
java8.util.stream.LongStream x = r.longs(-1L, -1L);
}, () -> {
java8.util.stream.LongStream x = r.longs(10, 1L, -2L);
}, () -> {
java8.util.stream.DoubleStream x = r.doubles(0.0, 0.0);
}, () -> {
java8.util.stream.DoubleStream x = r.doubles(10, .5, .4);
} };
assertThrows(IllegalArgumentException.class, throwingActions);
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedIntsCountSeq.
/**
* A sequential unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCountSeq() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.ints().limit(size).forEach(x -> counter.increment());
assertEquals(size, counter.sum());
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextIntBounded2.
/**
* nextInt(least, bound) returns least <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextIntBounded2() {
SplittableRandom sr = new SplittableRandom();
for (int least = -15485863; least < MAX_INT_BOUND; least += 524959) {
for (int bound = least + 2; bound > least && bound < MAX_INT_BOUND; bound += 49979687) {
int f = sr.nextInt(least, bound);
assertTrue(least <= f && f < bound);
int i = 0;
int j;
while (i < NCALLS && (j = sr.nextInt(least, bound)) == f) {
assertTrue(least <= j && j < bound);
++i;
}
assertTrue(i < NCALLS);
}
}
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextBytes_nullArray.
public void testNextBytes_nullArray() {
try {
new SplittableRandom().nextBytes(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
Aggregations