use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testBadStreamSize.
/**
* Invoking sized ints, long, doubles, with negative sizes throws
* IllegalArgumentException
*/
public void testBadStreamSize() {
ThreadLocalRandom r = ThreadLocalRandom.current();
Runnable[] throwingActions = { () -> r.ints(-1L), () -> r.ints(-1L, 2, 3), () -> r.longs(-1L), () -> r.longs(-1L, -1L, 1L), () -> r.doubles(-1L), () -> r.doubles(-1L, .5, .6) };
assertThrows(IllegalArgumentException.class, throwingActions);
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testDoublesCount.
/**
* A parallel sized stream of doubles generates the given number of values
*/
public void testDoublesCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.doubles(size).parallel().forEach(x -> counter.increment());
assertEquals(size, counter.sum());
size += 524959;
}
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testLongsCount.
/**
* A parallel sized stream of longs generates the given number of values
*/
public void testLongsCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.longs(size).parallel().forEach(x -> counter.increment());
assertEquals(size, counter.sum());
size += 524959;
}
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testUnsizedIntsCount.
/**
* A parallel unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.ints().limit(size).parallel().forEach(x -> counter.increment());
assertEquals(size, counter.sum());
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testBoundedDoubles.
/**
* Each of a parallel sized stream of bounded doubles is within bounds
*/
public void testBoundedDoubles() {
AtomicInteger fails = new AtomicInteger(0);
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 456;
for (double least = 0.00011; least < 1.0e20; least *= 9) {
for (double bound = least * 1.0011; bound < 1.0e20; bound *= 17) {
final double lo = least, hi = bound;
r.doubles(size, lo, hi).parallel().forEach(x -> {
if (x < lo || x >= hi)
fails.getAndIncrement();
});
}
}
assertEquals(0, fails.get());
}
Aggregations