use of java8.util.concurrent.atomic.LongAccumulator 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.util.concurrent.atomic.LongAccumulator 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.util.concurrent.atomic.LongAccumulator 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());
}
use of java8.util.concurrent.atomic.LongAccumulator in project streamsupport by stefan-zobel.
the class LongAccumulatorTest method testFloatValue.
/**
* floatValue returns current value.
*/
public void testFloatValue() {
LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
assertEquals(0.0f, acc.floatValue());
acc.accumulate(1);
assertEquals(1.0f, acc.floatValue());
}
Aggregations