Search in sources :

Example 6 with SplittableRandom

use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testNextInt.

/**
 * Repeated calls to nextInt produce at least two distinct results
 */
public void testNextInt() {
    SplittableRandom sr = new SplittableRandom();
    int f = sr.nextInt();
    int i = 0;
    while (i < NCALLS && sr.nextInt() == f) ++i;
    assertTrue(i < NCALLS);
}
Also used : SplittableRandom(java8.util.SplittableRandom)

Example 7 with SplittableRandom

use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testNextDouble.

/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f) ++i;
    assertTrue(i < NCALLS);
}
Also used : SplittableRandom(java8.util.SplittableRandom)

Example 8 with SplittableRandom

use of java8.util.SplittableRandom 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() {
    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(x -> counter.increment());
        assertEquals(size, counter.sum());
        size += 524959;
    }
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Example 9 with SplittableRandom

use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testDoublesCount.

/**
 * A parallel sized stream of doubles generates the given number of values
 */
public void testDoublesCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.doubles(size).parallel().forEach(x -> counter.increment());
        assertEquals(size, counter.sum());
        size += 524959;
    }
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Example 10 with SplittableRandom

use of java8.util.SplittableRandom in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testNextLong.

/**
 * Repeated calls to nextLong produce at least two distinct results
 */
public void testNextLong() {
    SplittableRandom sr = new SplittableRandom();
    long f = sr.nextLong();
    int i = 0;
    while (i < NCALLS && sr.nextLong() == f) ++i;
    assertTrue(i < NCALLS);
}
Also used : SplittableRandom(java8.util.SplittableRandom)

Aggregations

SplittableRandom (java8.util.SplittableRandom)66 LongAdder (java8.util.concurrent.atomic.LongAdder)18 Test (org.testng.annotations.Test)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 DoubleConsumer (java8.util.function.DoubleConsumer)4 IntConsumer (java8.util.function.IntConsumer)4 LongConsumer (java8.util.function.LongConsumer)4 ArrayList (java.util.ArrayList)3 Comparator (java.util.Comparator)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Spliterator (java8.util.Spliterator)3 Spliterators (java8.util.Spliterators)3 Consumer (java8.util.function.Consumer)3 Function (java8.util.function.Function)3 DoubleStream (java8.util.stream.DoubleStream)3 DoubleStreamTestScenario (java8.util.stream.DoubleStreamTestScenario)3 IntStream (java8.util.stream.IntStream)3 IntStreamTestScenario (java8.util.stream.IntStreamTestScenario)3