use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class DoubleAccumulatorTest method testLongValue.
/**
* longValue returns current value.
*/
public void testLongValue() {
DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
assertEquals(0, acc.longValue());
acc.accumulate(1.0);
assertEquals(1, acc.longValue());
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class DoubleAccumulatorTest method testAccumulateAndGet.
/**
* accumulate accumulates given value to current, and get returns current value
*/
public void testAccumulateAndGet() {
DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
acc.accumulate(2.0);
assertEquals(2.0, acc.get());
acc.accumulate(-4.0);
assertEquals(2.0, acc.get());
acc.accumulate(4.0);
assertEquals(4.0, acc.get());
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class DoubleAccumulatorTest method testDoubleValue.
/**
* doubleValue returns current value.
*/
public void testDoubleValue() {
DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
assertEquals(0.0, acc.doubleValue());
acc.accumulate(1.0);
assertEquals(1.0, acc.doubleValue());
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testUnsizedDoublesCount.
/**
* A parallel unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
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 ThreadLocalRandom8Test method testUnsizedDoublesCountSeq.
/**
* A sequential unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.doubles().limit(size).forEach(x -> counter.increment());
assertEquals(size, counter.sum());
}
Aggregations