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() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.doubles().limit(size).parallel().forEach(x -> counter.increment());
assertEquals(size, counter.sum());
}
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() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.doubles().limit(size).forEach(x -> counter.increment());
assertEquals(size, counter.sum());
}
use of java8.lang.Doubles 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() {
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(0, fails.get());
}
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
*/
@SuppressWarnings("unused")
public void testBadStreamSize() {
SplittableRandom r = new SplittableRandom();
Runnable[] throwingActions = { () -> {
java8.util.stream.IntStream x = r.ints(-1L);
}, () -> {
java8.util.stream.IntStream x = r.ints(-1L, 2, 3);
}, () -> {
java8.util.stream.LongStream x = r.longs(-1L);
}, () -> {
java8.util.stream.LongStream x = r.longs(-1L, -1L, 1L);
}, () -> {
java8.util.stream.DoubleStream x = r.doubles(-1L);
}, () -> {
java8.util.stream.DoubleStream x = r.doubles(-1L, .5, .6);
} };
assertThrows(IllegalArgumentException.class, throwingActions);
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class DoubleAccumulatorTest method testToString.
/**
* toString returns current value.
*/
public void testToString() {
DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
assertEquals("0.0", acc.toString());
acc.accumulate(1.0);
assertEquals(Double.toString(1.0), acc.toString());
}
Aggregations