use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testLongsCount.
/**
* A parallel sized stream of longs generates the given number of values
*/
public void testLongsCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.longs(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
size += 524959;
}
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testBadStreamSize.
/**
* Invoking sized ints, long, doubles, with negative sizes throws
* IllegalArgumentException
*/
public void testBadStreamSize() {
SplittableRandom r = new SplittableRandom();
executeAndCatchIAE(() -> r.ints(-1L));
executeAndCatchIAE(() -> r.ints(-1L, 2, 3));
executeAndCatchIAE(() -> r.longs(-1L));
executeAndCatchIAE(() -> r.longs(-1L, -1L, 1L));
executeAndCatchIAE(() -> r.doubles(-1L));
executeAndCatchIAE(() -> r.doubles(-1L, .5, .6));
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testNextLongBounded.
/**
* nextLong(bound) returns 0 <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextLongBounded() {
SplittableRandom sr = new SplittableRandom();
for (long bound = 2; bound < MAX_LONG_BOUND; bound += 15485863) {
long f = sr.nextLong(bound);
assertTrue(0 <= f && f < bound);
int i = 0;
long j;
while (i < NCALLS && (j = sr.nextLong(bound)) == f) {
assertTrue(0 <= j && j < bound);
++i;
}
assertTrue(i < NCALLS);
}
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testNextDoubleBadBound.
/**
* nextDouble(bound) throws IllegalArgumentException
*/
public void testNextDoubleBadBound() {
SplittableRandom sr = new SplittableRandom();
executeAndCatchIAE(() -> sr.nextDouble(0.0));
executeAndCatchIAE(() -> sr.nextDouble(-0.0));
executeAndCatchIAE(() -> sr.nextDouble(+0.0));
executeAndCatchIAE(() -> sr.nextDouble(-1.0));
executeAndCatchIAE(() -> sr.nextDouble(Double.NaN));
executeAndCatchIAE(() -> sr.nextDouble(Double.NEGATIVE_INFINITY));
// Returns Double.MAX_VALUE
// executeAndCatchIAE(() -> r.nextDouble(Double.POSITIVE_INFINITY));
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testUnsizedLongsCount.
/**
* A parallel unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.longs().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
Aggregations