use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testBadStreamSize.
/**
* Invoking sized ints, long, doubles, with negative sizes throws
* IllegalArgumentException
*/
public void testBadStreamSize() {
ThreadLocalRandom r = ThreadLocalRandom.current();
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 java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest 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(counter.sum(), size);
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testIntsCount.
/**
* A parallel sized stream of ints generates the given number of values
*/
public void testIntsCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.ints(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
size += 524959;
}
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testUnsizedLongsCount.
/**
* A parallel unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.longs().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest 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(counter.sum(), size);
size += 524959;
}
}
Aggregations