use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testDoublesCount.
/**
* A parallel sized stream of doubles generates the given number of values
*/
public void testDoublesCount() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.doubles(size).parallel().forEach(new DoubleConsumer() {
@Override
public void accept(double x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
size += 524959;
}
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testLongsCount.
/**
* A parallel sized stream of longs generates the given number of values
*/
public void testLongsCount() {
final 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(new LongConsumer() {
@Override
public void accept(long x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
size += 524959;
}
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextIntBounded2.
/**
* nextInt(least, bound) returns least <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextIntBounded2() {
SplittableRandom sr = new SplittableRandom();
for (int least = -15485863; least < MAX_INT_BOUND; least += 524959) {
for (int bound = least + 2; bound > least && bound < MAX_INT_BOUND; bound += 49979687) {
int f = sr.nextInt(least, bound);
assertTrue(least <= f && f < bound);
int i = 0;
int j;
while (i < NCALLS && (j = sr.nextInt(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 testNextLongBadBounds.
/**
* nextLong(least >= bound) throws IllegalArgumentException
*/
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNextLongBadBounds() {
SplittableRandom sr = new SplittableRandom();
long f = sr.nextLong(17, 2);
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testBoundedDoubles.
/**
* Each of a parallel sized stream of bounded doubles is within bounds
*/
public void testBoundedDoubles() {
final AtomicInteger fails = new AtomicInteger(0);
SplittableRandom r = new SplittableRandom();
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(new DoubleConsumer() {
@Override
public void accept(double x) {
if (x < lo || x >= hi)
fails.getAndIncrement();
}
});
}
}
assertEquals(fails.get(), 0);
}
Aggregations