use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testUnsizedIntsCount.
/**
* A parallel unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCount() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 100;
r.ints().limit(size).parallel().forEach(new IntConsumer() {
@Override
public void accept(int x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
}
use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class StringJoinerTest method addAlladdAll.
// The following tests do two successive adds of different types
public void addAlladdAll() {
final StringJoiner sj = new StringJoiner(DASH, "{", "}");
ArrayList<String> firstOne = new ArrayList<String>();
firstOne.add(ONE);
firstOne.add(TWO);
firstOne.add(THREE);
Stream<String> stream = StreamSupport.stream(firstOne);
stream.forEachOrdered(new java8.util.function.Consumer<String>() {
@Override
public void accept(String t) {
sj.add(t);
}
});
ArrayList<String> nextOne = new ArrayList<String>();
nextOne.add(FOUR);
nextOne.add(FIVE);
Stream<String> stream2 = StreamSupport.stream(nextOne);
stream2.forEachOrdered(new java8.util.function.Consumer<String>() {
@Override
public void accept(String t) {
sj.add(t);
}
});
String expected = "{" + ONE + DASH + TWO + DASH + THREE + DASH + FOUR + DASH + FIVE + "}";
assertEquals(sj.toString(), expected);
}
use of java8.util.stream.Stream 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;
}
}
use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testUnsizedLongsCountSeq.
/**
* A sequential unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.longs().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java8.util.stream.Stream in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testUnsizedIntsCountSeq.
/**
* A sequential unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.ints().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
Aggregations