Search in sources :

Example 21 with Longs

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());
}
Also used : LongAccumulator(java8.util.concurrent.atomic.LongAccumulator) Longs(java8.lang.Longs)

Example 22 with Longs

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SplittableRandom(java8.util.SplittableRandom)

Example 23 with Longs

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());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java8.util.concurrent.ThreadLocalRandom)

Example 24 with Longs

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;
    }
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java8.util.concurrent.ThreadLocalRandom)

Example 25 with Longs

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());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java8.util.concurrent.ThreadLocalRandom)

Aggregations

LongAdder (java8.util.concurrent.atomic.LongAdder)12 SplittableRandom (java8.util.SplittableRandom)9 Longs (java8.lang.Longs)8 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)8 LongAccumulator (java8.util.concurrent.atomic.LongAccumulator)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 LongConsumer (java8.util.function.LongConsumer)4 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Spliterator (java8.util.Spliterator)1 Spliterators (java8.util.Spliterators)1 Consumer (java8.util.function.Consumer)1 Function (java8.util.function.Function)1 DoubleStream (java8.util.stream.DoubleStream)1 DoubleStreamTestScenario (java8.util.stream.DoubleStreamTestScenario)1 IntStream (java8.util.stream.IntStream)1 IntStreamTestScenario (java8.util.stream.IntStreamTestScenario)1