Search in sources :

Example 26 with SplittableRandom

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

the class SplittableRandomTest method testSplit1.

/**
 * A SplittableRandom produced by split() of a default-constructed
 * SplittableRandom generates a different sequence
 */
public void testSplit1() {
    SplittableRandom sr = new SplittableRandom();
    for (int reps = 0; reps < REPS; ++reps) {
        SplittableRandom sc = sr.split();
        int i = 0;
        while (i < NCALLS && sr.nextLong() == sc.nextLong()) ++i;
        assertTrue(i < NCALLS);
    }
}
Also used : SplittableRandom(java8.util.SplittableRandom)

Example 27 with SplittableRandom

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

the class SplittableRandomTest method testNextLongBoundedNeg.

/**
 * nextLong(negative) throws IllegalArgumentException
 */
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNextLongBoundedNeg() {
    SplittableRandom sr = new SplittableRandom();
    long f = sr.nextLong(-17);
}
Also used : SplittableRandom(java8.util.SplittableRandom) Test(org.testng.annotations.Test)

Example 28 with SplittableRandom

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

the class SplittableRandomTest method testNextIntBadBounds.

/**
 * nextInt(least >= bound) throws IllegalArgumentException
 */
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNextIntBadBounds() {
    SplittableRandom sr = new SplittableRandom();
    int f = sr.nextInt(17, 2);
}
Also used : SplittableRandom(java8.util.SplittableRandom) Test(org.testng.annotations.Test)

Example 29 with SplittableRandom

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

the class SplittableRandomTest method testUnsizedIntsCountSeq.

/**
 * A sequential unsized stream of ints generates at least 100 values
 */
public void testUnsizedIntsCountSeq() {
    final LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.ints().limit(size).forEach(new IntConsumer() {

        @Override
        public void accept(int x) {
            counter.increment();
        }
    });
    assertEquals(counter.sum(), size);
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom) IntConsumer(java8.util.function.IntConsumer)

Example 30 with SplittableRandom

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

the class SplittableRandomTest method testNextIntBounded.

/**
 * nextInt(bound) returns 0 <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextIntBounded() {
    SplittableRandom sr = new SplittableRandom();
    // sample bound space across prime number increments
    for (int bound = 2; bound < MAX_INT_BOUND; bound += 524959) {
        int f = sr.nextInt(bound);
        assertTrue(0 <= f && f < bound);
        int i = 0;
        int j;
        while (i < NCALLS && (j = sr.nextInt(bound)) == f) {
            assertTrue(0 <= j && j < bound);
            ++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