Search in sources :

Example 46 with Stream

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

Example 47 with Stream

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

Example 48 with Stream

use of java8.util.stream.Stream 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() {
    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(x -> {
                if (x < lo || x >= hi)
                    fails.getAndIncrement();
            });
        }
    }
    assertEquals(0, fails.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SplittableRandom(java8.util.SplittableRandom)

Example 49 with Stream

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

the class SplittableRandomTest method testBoundedInts.

/**
 * Each of a parallel sized stream of bounded ints is within bounds
 */
public void testBoundedInts() {
    AtomicInteger fails = new AtomicInteger(0);
    SplittableRandom r = new SplittableRandom();
    long size = 12345L;
    for (int least = -15485867; least < MAX_INT_BOUND; least += 524959) {
        for (int bound = least + 2; bound > least && bound < MAX_INT_BOUND; bound += 67867967) {
            final int lo = least, hi = bound;
            r.ints(size, lo, hi).parallel().forEach(x -> {
                if (x < lo || x >= hi)
                    fails.getAndIncrement();
            });
        }
    }
    assertEquals(0, fails.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SplittableRandom(java8.util.SplittableRandom)

Example 50 with Stream

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

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

Aggregations

LongAdder (java8.util.concurrent.atomic.LongAdder)36 SplittableRandom (java8.util.SplittableRandom)27 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)25 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)9 Function (java8.util.function.Function)8 OpTestCase (java8.util.stream.OpTestCase)8 List (java.util.List)7 StreamSupport (java8.util.stream.StreamSupport)7 TestData (java8.util.stream.TestData)7 Set (java.util.Set)6 Supplier (java8.util.function.Supplier)6 DoubleStream (java8.util.stream.DoubleStream)6 IntStream (java8.util.stream.IntStream)6 LongStream (java8.util.stream.LongStream)6 HashSet (java.util.HashSet)5 Spliterator (java8.util.Spliterator)5 Consumer (java8.util.function.Consumer)5 Collection (java.util.Collection)4