Search in sources :

Example 16 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testUnsizedDoublesCountSeq.

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

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

Example 17 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testBadStreamSize.

/**
 * Invoking sized ints, long, doubles, with negative sizes throws
 * IllegalArgumentException
 */
public void testBadStreamSize() {
    final SplittableRandom r = new SplittableRandom();
    executeAndCatchIAE(new Runnable() {

        @Override
        public void run() {
            r.ints(-1L);
        }
    });
    executeAndCatchIAE(new Runnable() {

        @Override
        public void run() {
            r.ints(-1L, 2, 3);
        }
    });
    executeAndCatchIAE(new Runnable() {

        @Override
        public void run() {
            r.longs(-1L);
        }
    });
    executeAndCatchIAE(new Runnable() {

        @Override
        public void run() {
            r.longs(-1L, -1L, 1L);
        }
    });
    executeAndCatchIAE(new Runnable() {

        @Override
        public void run() {
            r.doubles(-1L);
        }
    });
    executeAndCatchIAE(new Runnable() {

        @Override
        public void run() {
            r.doubles(-1L, .5, .6);
        }
    });
}
Also used : SplittableRandom(java8.util.SplittableRandom)

Example 18 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testUnsizedDoublesCount.

/**
 * A parallel unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCount() {
    final LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.doubles().limit(size).parallel().forEach(new DoubleConsumer() {

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

Example 19 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class ThreadLocalRandomTest method testDoublesCount.

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

Example 20 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class ThreadLocalRandomTest method testBadStreamBounds.

/**
 * Invoking bounded ints, long, doubles, with illegal bounds throws
 * IllegalArgumentException
 */
public void testBadStreamBounds() {
    ThreadLocalRandom r = ThreadLocalRandom.current();
    executeAndCatchIAE(() -> r.ints(2, 1));
    executeAndCatchIAE(() -> r.ints(10, 42, 42));
    executeAndCatchIAE(() -> r.longs(-1L, -1L));
    executeAndCatchIAE(() -> r.longs(10, 1L, -2L));
    testDoubleBadOriginBound((o, b) -> r.doubles(10, o, b));
}
Also used : ThreadLocalRandom(java8.util.concurrent.ThreadLocalRandom)

Aggregations

SplittableRandom (java8.util.SplittableRandom)13 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)12 LongAdder (java8.util.concurrent.atomic.LongAdder)12 Doubles (java8.lang.Doubles)8 DoubleAccumulator (java8.util.concurrent.atomic.DoubleAccumulator)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DoubleConsumer (java8.util.function.DoubleConsumer)4 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Spliterator (java8.util.Spliterator)1 Spliterators (java8.util.Spliterators)1 Consumer (java8.util.function.Consumer)1 Function (java8.util.function.Function)1 DoubleStream (java8.util.stream.DoubleStream)1 DoubleStreamTestScenario (java8.util.stream.DoubleStreamTestScenario)1 IntStream (java8.util.stream.IntStream)1 IntStreamTestScenario (java8.util.stream.IntStreamTestScenario)1