Search in sources :

Example 6 with Doubles

use of java8.lang.Doubles 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 7 with Doubles

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

the class ThreadLocalRandom8Test method testBadStreamBounds.

/**
 * Invoking bounded ints, long, doubles, with illegal bounds throws
 * IllegalArgumentException
 */
public void testBadStreamBounds() {
    ThreadLocalRandom r = ThreadLocalRandom.current();
    Runnable[] throwingActions = { () -> r.ints(2, 1), () -> r.ints(10, 42, 42), () -> r.longs(-1L, -1L), () -> r.longs(10, 1L, -2L), () -> r.doubles(0.0, 0.0), () -> r.doubles(10, .5, .4) };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
Also used : ThreadLocalRandom(java8.util.concurrent.ThreadLocalRandom)

Example 8 with Doubles

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

the class SplittableRandomTest method testDoublesCount.

/**
 * A parallel sized stream of doubles generates the given number of values
 */
public void testDoublesCount() {
    final LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.doubles(size).parallel().forEach(new DoubleConsumer() {

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

Example 9 with Doubles

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

the class SplittableRandomTest method testBoundedDoubles.

/**
 * Each of a parallel sized stream of bounded doubles is within bounds
 */
public void testBoundedDoubles() {
    final AtomicInteger fails = new AtomicInteger(0);
    SplittableRandom r = new SplittableRandom();
    long size = 456;
    for (double least = 0.00011; least < 1.0e20; least *= 9) {
        for (double bound = least * 1.0011; bound < 1.0e20; bound *= 17) {
            final double lo = least, hi = bound;
            r.doubles(size, lo, hi).parallel().forEach(new DoubleConsumer() {

                @Override
                public void accept(double x) {
                    if (x < lo || x >= hi)
                        fails.getAndIncrement();
                }
            });
        }
    }
    assertEquals(fails.get(), 0);
}
Also used : DoubleConsumer(java8.util.function.DoubleConsumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SplittableRandom(java8.util.SplittableRandom)

Example 10 with Doubles

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

the class SplittableRandomTest method testBadStreamBounds.

/**
 * Invoking bounded ints, long, doubles, with illegal bounds throws
 * IllegalArgumentException
 */
public void testBadStreamBounds() {
    final SplittableRandom r = new SplittableRandom();
    executeAndCatchIAE(new Runnable() {

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

        @Override
        public void run() {
            r.ints(10, 42, 42);
        }
    });
    executeAndCatchIAE(new Runnable() {

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

        @Override
        public void run() {
            r.longs(10, 1L, -2L);
        }
    });
    testDoubleBadOriginBound(new BiConsumer<Double, Double>() {

        @Override
        public void accept(Double o, Double b) {
            r.doubles(10, o, b);
        }
    });
}
Also used : SplittableRandom(java8.util.SplittableRandom)

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