use of java8.lang.Longs 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());
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testBoundedLongs.
/**
* Each of a parallel sized stream of bounded longs is within bounds
*/
public void testBoundedLongs() {
AtomicInteger fails = new AtomicInteger(0);
SplittableRandom r = new SplittableRandom();
long size = 123L;
for (long least = -86028121; least < MAX_LONG_BOUND; least += 1982451653L) {
for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
final long lo = least, hi = bound;
r.longs(size, lo, hi).parallel().forEach(x -> {
if (x < lo || x >= hi)
fails.getAndIncrement();
});
}
}
assertEquals(0, fails.get());
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testUnsizedLongsCount.
/**
* A parallel unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
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 ThreadLocalRandom8Test method testLongsCount.
/**
* A parallel sized stream of longs generates the given number of values
*/
public void testLongsCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.longs(size).parallel().forEach(x -> counter.increment());
assertEquals(size, counter.sum());
size += 524959;
}
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test 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(size, counter.sum());
}
Aggregations