use of java8.util.concurrent.atomic.LongAdder 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.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testUnsizedIntsCountSeq.
/**
* A sequential unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.ints().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class LongAdderTest method testToString.
/**
* toString returns current value.
*/
public void testToString() {
LongAdder ai = new LongAdder();
assertEquals("0", ai.toString());
ai.increment();
assertEquals(Long.toString(1), ai.toString());
}
use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class LongAdderTest method testFloatValue.
/**
* floatValue returns current value.
*/
public void testFloatValue() {
LongAdder ai = new LongAdder();
assertEquals(0.0f, ai.floatValue());
ai.increment();
assertEquals(1.0f, ai.floatValue());
}
use of java8.util.concurrent.atomic.LongAdder in project streamsupport by stefan-zobel.
the class LongAdderTest method testSumThenReset.
/**
* sumThenReset() returns sum; subsequent sum() returns zero
*/
public void testSumThenReset() {
LongAdder ai = new LongAdder();
ai.add(2);
assertEquals(2, ai.sum());
assertEquals(2, ai.sumThenReset());
assertEquals(0, ai.sum());
}
Aggregations