use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextDoubleBadBound.
/**
* nextDouble(bound) throws IllegalArgumentException
*/
public void testNextDoubleBadBound() {
final SplittableRandom sr = new SplittableRandom();
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
sr.nextDouble(0.0);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
sr.nextDouble(-0.0);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
sr.nextDouble(+0.0);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
sr.nextDouble(-1.0);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
sr.nextDouble(Double.NaN);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
sr.nextDouble(Double.NEGATIVE_INFINITY);
}
});
// Returns Double.MAX_VALUE
// executeAndCatchIAE(() -> r.nextDouble(Double.POSITIVE_INFINITY));
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testNextInt.
/**
* Repeated calls to nextInt produce at least two distinct results
*/
public void testNextInt() {
SplittableRandom sr = new SplittableRandom();
int f = sr.nextInt();
int i = 0;
while (i < NCALLS && sr.nextInt() == f) ++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 (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 testUnsizedLongsCountSeq.
/**
* A sequential unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCountSeq() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.longs().limit(size).forEach(new LongConsumer() {
@Override
public void accept(long x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedDoublesCount.
/**
* A parallel unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCount() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.doubles().limit(size).parallel().forEach(new DoubleConsumer() {
@Override
public void accept(double x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
Aggregations