use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testSplit1.
/**
* A SplittableRandom produced by split() of a default-constructed
* SplittableRandom generates a different sequence
*/
public void testSplit1() {
SplittableRandom sr = new SplittableRandom();
for (int reps = 0; reps < REPS; ++reps) {
SplittableRandom sc = sr.split();
int i = 0;
while (i < NCALLS && sr.nextLong() == sc.nextLong()) ++i;
assertTrue(i < NCALLS);
}
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextLongBoundedNeg.
/**
* nextLong(negative) throws IllegalArgumentException
*/
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNextLongBoundedNeg() {
SplittableRandom sr = new SplittableRandom();
long f = sr.nextLong(-17);
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextIntBadBounds.
/**
* nextInt(least >= bound) throws IllegalArgumentException
*/
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNextIntBadBounds() {
SplittableRandom sr = new SplittableRandom();
int f = sr.nextInt(17, 2);
}
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() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.ints().limit(size).forEach(new IntConsumer() {
@Override
public void accept(int x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextIntBounded.
/**
* nextInt(bound) returns 0 <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextIntBounded() {
SplittableRandom sr = new SplittableRandom();
// sample bound space across prime number increments
for (int bound = 2; bound < MAX_INT_BOUND; bound += 524959) {
int f = sr.nextInt(bound);
assertTrue(0 <= f && f < bound);
int i = 0;
int j;
while (i < NCALLS && (j = sr.nextInt(bound)) == f) {
assertTrue(0 <= j && j < bound);
++i;
}
assertTrue(i < NCALLS);
}
}
Aggregations