Search in sources :

Example 26 with SplittableRandom

use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.

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(counter.sum(), size);
        size += 524959;
    }
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) SplittableRandom(java.util.SplittableRandom)

Example 27 with SplittableRandom

use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.

the class SplittableRandomTest method testBadStreamSize.

/**
     * Invoking sized ints, long, doubles, with negative sizes throws
     * IllegalArgumentException
     */
public void testBadStreamSize() {
    SplittableRandom r = new SplittableRandom();
    executeAndCatchIAE(() -> r.ints(-1L));
    executeAndCatchIAE(() -> r.ints(-1L, 2, 3));
    executeAndCatchIAE(() -> r.longs(-1L));
    executeAndCatchIAE(() -> r.longs(-1L, -1L, 1L));
    executeAndCatchIAE(() -> r.doubles(-1L));
    executeAndCatchIAE(() -> r.doubles(-1L, .5, .6));
}
Also used : SplittableRandom(java.util.SplittableRandom)

Example 28 with SplittableRandom

use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.

the class SplittableRandomTest method testNextLongBounded.

/**
     * nextLong(bound) returns 0 <= value < bound;
     * repeated calls produce at least two distinct results
     */
public void testNextLongBounded() {
    SplittableRandom sr = new SplittableRandom();
    for (long bound = 2; bound < MAX_LONG_BOUND; bound += 15485863) {
        long f = sr.nextLong(bound);
        assertTrue(0 <= f && f < bound);
        int i = 0;
        long j;
        while (i < NCALLS && (j = sr.nextLong(bound)) == f) {
            assertTrue(0 <= j && j < bound);
            ++i;
        }
        assertTrue(i < NCALLS);
    }
}
Also used : SplittableRandom(java.util.SplittableRandom)

Example 29 with SplittableRandom

use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.

the class SplittableRandomTest method testNextDoubleBadBound.

/**
     * nextDouble(bound) throws IllegalArgumentException
     */
public void testNextDoubleBadBound() {
    SplittableRandom sr = new SplittableRandom();
    executeAndCatchIAE(() -> sr.nextDouble(0.0));
    executeAndCatchIAE(() -> sr.nextDouble(-0.0));
    executeAndCatchIAE(() -> sr.nextDouble(+0.0));
    executeAndCatchIAE(() -> sr.nextDouble(-1.0));
    executeAndCatchIAE(() -> sr.nextDouble(Double.NaN));
    executeAndCatchIAE(() -> sr.nextDouble(Double.NEGATIVE_INFINITY));
// Returns Double.MAX_VALUE
//        executeAndCatchIAE(() -> r.nextDouble(Double.POSITIVE_INFINITY));
}
Also used : SplittableRandom(java.util.SplittableRandom)

Example 30 with SplittableRandom

use of java.util.SplittableRandom in project jdk8u_jdk by JetBrains.

the class SplittableRandomTest method testUnsizedLongsCount.

/**
     * A parallel unsized stream of longs generates at least 100 values
     */
public void testUnsizedLongsCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.longs().limit(size).parallel().forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) SplittableRandom(java.util.SplittableRandom)

Aggregations

SplittableRandom (java.util.SplittableRandom)34 LongAdder (java.util.concurrent.atomic.LongAdder)9 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Spliterator (java.util.Spliterator)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Consumer (java.util.function.Consumer)3 Function (java.util.function.Function)3 DoubleStream (java.util.stream.DoubleStream)3 DoubleStreamTestScenario (java.util.stream.DoubleStreamTestScenario)3 IntStream (java.util.stream.IntStream)3 IntStreamTestScenario (java.util.stream.IntStreamTestScenario)3 LongStream (java.util.stream.LongStream)3 LongStreamTestScenario (java.util.stream.LongStreamTestScenario)3 OpTestCase (java.util.stream.OpTestCase)3 StreamSupport (java.util.stream.StreamSupport)3 TestData (java.util.stream.TestData)3