use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextDoubleBounded2.
// TODO: Test infinite bounds!
// () -> sr.nextDouble(Double.NEGATIVE_INFINITY, 0.0d),
// () -> sr.nextDouble(0.0d, Double.POSITIVE_INFINITY),
/**
* nextDouble(least, bound) returns least <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextDoubleBounded2() {
SplittableRandom sr = new SplittableRandom();
for (double least = 0.0001; least < 1.0e20; least *= 8) {
for (double bound = least * 1.001; bound < 1.0e20; bound *= 16) {
double f = sr.nextDouble(least, bound);
assertTrue(least <= f && f < bound);
int i = 0;
double j;
while (i < NCALLS && (j = sr.nextDouble(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 testNextLongBounded.
/**
* nextLong(bound) returns 0 <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextLongBounded() {
SplittableRandom sr = new SplittableRandom();
for (int i = 0; i < 2; i++) assertEquals(0L, sr.nextLong(1L));
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 java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextIntBounded.
/**
* nextInt(bound) returns 0 <= value < bound;
* repeated calls produce at least two distinct results
*/
public void testNextIntBounded() {
SplittableRandom sr = new SplittableRandom();
for (int i = 0; i < 2; i++) assertEquals(0, sr.nextInt(1));
// sample bound space across prime number increments
for (int bound = 2; bound < MAX_INT_BOUND; bound += 524959) {
int f = sr.nextInt(bound);
assertTrue(0 <= f && f < bound);
int i = 0;
int j;
while (i < NCALLS && (j = sr.nextInt(bound)) == f) {
assertTrue(0 <= j && j < bound);
++i;
}
assertTrue(i < NCALLS);
}
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testSplit2.
/**
* A SplittableRandom produced by split() of a seeded-constructed
* SplittableRandom generates a different sequence
*/
public void testSplit2() {
SplittableRandom sr = new SplittableRandom(12345);
for (int reps = 0; reps < REPS; ++reps) {
SplittableRandom sc = sr.split();
int i = 0;
while (i < NCALLS && sr.nextLong() == sc.nextLong()) ++i;
assertTrue(i < NCALLS);
}
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testBoundedLongs.
/**
* Each of a parallel sized stream of bounded longs is within bounds
*/
public void testBoundedLongs() {
final AtomicInteger fails = new AtomicInteger(0);
SplittableRandom r = new SplittableRandom();
long size = 123L;
for (long least = -86028121; least < MAX_LONG_BOUND; least += 1982451653L) {
for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
final long lo = least, hi = bound;
r.longs(size, lo, hi).parallel().forEach(new LongConsumer() {
@Override
public void accept(long x) {
if (x < lo || x >= hi)
fails.getAndIncrement();
}
});
}
}
assertEquals(fails.get(), 0);
}
Aggregations