Search in sources :

Example 11 with SplittableRandom

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

the class SplittableRandomTest method testNextLongBadBounds.

/**
 * nextLong(least >= bound) throws IllegalArgumentException
 */
public void testNextLongBadBounds() {
    SplittableRandom sr = new SplittableRandom();
    Runnable[] throwingActions = { () -> sr.nextLong(17L, 2L), () -> sr.nextLong(-42L, -42L), () -> sr.nextLong(Long.MAX_VALUE, Long.MIN_VALUE) };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
Also used : SplittableRandom(java8.util.SplittableRandom)

Example 12 with SplittableRandom

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

the class SplittableRandomTest method testBadStreamBounds.

/**
 * Invoking bounded ints, long, doubles, with illegal bounds throws
 * IllegalArgumentException
 */
@SuppressWarnings("unused")
public void testBadStreamBounds() {
    SplittableRandom r = new SplittableRandom();
    Runnable[] throwingActions = { () -> {
        java8.util.stream.IntStream x = r.ints(2, 1);
    }, () -> {
        java8.util.stream.IntStream x = r.ints(10, 42, 42);
    }, () -> {
        java8.util.stream.LongStream x = r.longs(-1L, -1L);
    }, () -> {
        java8.util.stream.LongStream x = r.longs(10, 1L, -2L);
    }, () -> {
        java8.util.stream.DoubleStream x = r.doubles(0.0, 0.0);
    }, () -> {
        java8.util.stream.DoubleStream x = r.doubles(10, .5, .4);
    } };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
Also used : SplittableRandom(java8.util.SplittableRandom)

Example 13 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() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.ints().limit(size).forEach(x -> counter.increment());
    assertEquals(size, counter.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Example 14 with SplittableRandom

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

the class SplittableRandomTest method testNextIntBounded2.

/**
 * nextInt(least, bound) returns least <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextIntBounded2() {
    SplittableRandom sr = new SplittableRandom();
    for (int least = -15485863; least < MAX_INT_BOUND; least += 524959) {
        for (int bound = least + 2; bound > least && bound < MAX_INT_BOUND; bound += 49979687) {
            int f = sr.nextInt(least, bound);
            assertTrue(least <= f && f < bound);
            int i = 0;
            int j;
            while (i < NCALLS && (j = sr.nextInt(least, bound)) == f) {
                assertTrue(least <= j && j < bound);
                ++i;
            }
            assertTrue(i < NCALLS);
        }
    }
}
Also used : SplittableRandom(java8.util.SplittableRandom)

Example 15 with SplittableRandom

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

the class SplittableRandomTest method testNextBytes_nullArray.

public void testNextBytes_nullArray() {
    try {
        new SplittableRandom().nextBytes(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
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