Search in sources :

Example 1 with SplittableRandom

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

the class SplittableRandomTest method testNextLongBounded2.

/**
     * nextLong(least, bound) returns least <= value < bound;
     * repeated calls produce at least two distinct results
     */
public void testNextLongBounded2() {
    SplittableRandom sr = new SplittableRandom();
    for (long least = -86028121; least < MAX_LONG_BOUND; least += 982451653L) {
        for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
            long f = sr.nextLong(least, bound);
            assertTrue(least <= f && f < bound);
            int i = 0;
            long j;
            while (i < NCALLS && (j = sr.nextLong(least, bound)) == f) {
                assertTrue(least <= j && j < bound);
                ++i;
            }
            assertTrue(i < NCALLS);
        }
    }
}
Also used : SplittableRandom(java.util.SplittableRandom)

Example 2 with SplittableRandom

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

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(java.util.SplittableRandom)

Example 3 with SplittableRandom

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

the class SplittableRandomTest method testUnsizedDoublesCountSeq.

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

Example 4 with SplittableRandom

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

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(java.util.SplittableRandom) Test(org.testng.annotations.Test)

Example 5 with SplittableRandom

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

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(java.util.SplittableRandom)

Aggregations

SplittableRandom (java.util.SplittableRandom)39 LongAdder (java.util.concurrent.atomic.LongAdder)9 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)5 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