use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testNextIntBoundedNeg.
/**
* nextInt(negative) throws IllegalArgumentException
*/
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNextIntBoundedNeg() {
SplittableRandom sr = new SplittableRandom();
int f = sr.nextInt(-17);
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testIntsCount.
/**
* A parallel sized stream of ints generates the given number of values
*/
public void testIntsCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
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 java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testBoundedDoubles.
/**
* Each of a parallel sized stream of bounded doubles is within bounds
*/
public void testBoundedDoubles() {
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(x -> {
if (x < lo || x >= hi)
fails.getAndIncrement();
});
}
}
assertEquals(fails.get(), 0);
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
the class SplittableRandomTest method testSeedConstructor.
/**
* Two SplittableRandoms created with the same seed produce the
* same values for nextLong.
*/
public void testSeedConstructor() {
for (long seed = 2; seed < MAX_LONG_BOUND; seed += 15485863) {
SplittableRandom sr1 = new SplittableRandom(seed);
SplittableRandom sr2 = new SplittableRandom(seed);
for (int i = 0; i < REPS; ++i) assertEquals(sr1.nextLong(), sr2.nextLong());
}
}
use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.
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);
}
}
Aggregations