use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testUnsizedLongsCountSeq.
/**
* A sequential unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.longs().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedLongsCount.
/**
* A parallel unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCount() {
LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.longs().limit(size).parallel().forEach(x -> counter.increment());
assertEquals(size, counter.sum());
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class LongAccumulatorTest method testAccumulateAndGet.
/**
* accumulate accumulates given value to current, and get returns current value
*/
public void testAccumulateAndGet() {
LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
acc.accumulate(2);
assertEquals(2, acc.get());
acc.accumulate(-4);
assertEquals(2, acc.get());
acc.accumulate(4);
assertEquals(4, acc.get());
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class LongAccumulatorTest method testToString.
/**
* toString returns current value.
*/
public void testToString() {
LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
assertEquals("0", acc.toString());
acc.accumulate(1);
assertEquals(Long.toString(1), acc.toString());
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class LongAccumulatorTest method testReset.
/**
* reset() causes subsequent get() to return zero
*/
public void testReset() {
LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
acc.accumulate(2);
assertEquals(2, acc.get());
acc.reset();
assertEquals(0, acc.get());
}
Aggregations