use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedDoublesCountSeq.
/**
* A sequential unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCountSeq() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.doubles().limit(size).forEach(new DoubleConsumer() {
@Override
public void accept(double x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testBadStreamSize.
/**
* Invoking sized ints, long, doubles, with negative sizes throws
* IllegalArgumentException
*/
public void testBadStreamSize() {
final SplittableRandom r = new SplittableRandom();
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.ints(-1L);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.ints(-1L, 2, 3);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.longs(-1L);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.longs(-1L, -1L, 1L);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.doubles(-1L);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.doubles(-1L, .5, .6);
}
});
}
use of java8.lang.Doubles 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);
}
use of java8.lang.Doubles 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;
}
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testBadStreamBounds.
/**
* Invoking bounded ints, long, doubles, with illegal bounds throws
* IllegalArgumentException
*/
public void testBadStreamBounds() {
ThreadLocalRandom r = ThreadLocalRandom.current();
executeAndCatchIAE(() -> r.ints(2, 1));
executeAndCatchIAE(() -> r.ints(10, 42, 42));
executeAndCatchIAE(() -> r.longs(-1L, -1L));
executeAndCatchIAE(() -> r.longs(10, 1L, -2L));
testDoubleBadOriginBound((o, b) -> r.doubles(10, o, b));
}
Aggregations