use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextDoubleBoundNonPositive.
/**
* nextDouble(non-positive) throws IllegalArgumentException
*/
public void testNextDoubleBoundNonPositive() {
SplittableRandom sr = new SplittableRandom();
Runnable[] throwingActions = { () -> sr.nextDouble(-17.0d), () -> sr.nextDouble(0.0d), () -> sr.nextDouble(-Double.MIN_VALUE), () -> sr.nextDouble(Double.NEGATIVE_INFINITY), () -> sr.nextDouble(Double.NaN) };
assertThrows(IllegalArgumentException.class, throwingActions);
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testSeedConstructor.
/**
* Two SplittableRandoms created with the same seed produce the
* same values for nextLong.
*/
public void testSeedConstructor() {
for (long seed = 2; seed < MAX_LONG_BOUND; seed += 15485863) {
SplittableRandom sr1 = new SplittableRandom(seed);
SplittableRandom sr2 = new SplittableRandom(seed);
for (int i = 0; i < REPS; ++i) assertEquals(sr1.nextLong(), sr2.nextLong());
}
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextLongBounded2.
/**
* nextLong(least, bound) returns least <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextLongBounded2() {
SplittableRandom sr = new SplittableRandom();
for (long least = -86028121; least < MAX_LONG_BOUND; least += 982451653L) {
for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
long f = sr.nextLong(least, bound);
assertTrue(least <= f && f < bound);
int i = 0;
long j;
while (i < NCALLS && (j = sr.nextLong(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 testIntsCount.
/**
* A parallel sized stream of ints generates the given number of values
*/
public void testIntsCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.ints(size).parallel().forEach(x -> counter.increment());
assertEquals(size, counter.sum());
size += 524959;
}
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedLongsCountSeq.
/**
* A sequential unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCountSeq() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.longs().limit(size).forEach(x -> counter.increment());
assertEquals(size, counter.sum());
}
Aggregations