use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class LongAccumulatorTest method testGetThenReset.
/**
* getThenReset() returns current value; subsequent get() returns zero
*/
public void testGetThenReset() {
LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
acc.accumulate(2);
assertEquals(2, acc.get());
assertEquals(2, acc.getThenReset());
assertEquals(0, acc.get());
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testBoundedLongs.
/**
* Each of a parallel sized stream of bounded longs is within bounds
*/
public void testBoundedLongs() {
AtomicInteger fails = new AtomicInteger(0);
ThreadLocalRandom r = ThreadLocalRandom.current();
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 SplittableRandomTest method testBoundedLongs.
/**
* Each of a parallel sized stream of bounded longs is within bounds
*/
public void testBoundedLongs() {
final 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(new LongConsumer() {
@Override
public void accept(long x) {
if (x < lo || x >= hi)
fails.getAndIncrement();
}
});
}
}
assertEquals(fails.get(), 0);
}
use of java8.lang.Longs in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testLongsCount.
/**
* A parallel sized stream of longs generates the given number of values
*/
public void testLongsCount() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.longs(size).parallel().forEach(new LongConsumer() {
@Override
public void accept(long x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
size += 524959;
}
}
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() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.longs().limit(size).parallel().forEach(new LongConsumer() {
@Override
public void accept(long x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
Aggregations