@Test public void parallelStreamWithBuilder() { Builder builder = IntStream.builder(); builder.accept(42); IntStream stream = ParallelIntStreamSupport.parallelStream(builder, this.workerPool); assertThat(stream, instanceOf(ParallelIntStreamSupport.class)); assertTrue(stream.isParallel()); assertEquals(OptionalInt.of(42), stream.findAny()); }
@Test public void testDropWhile() { assertArrayEquals(new int[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, IntStreamEx.range(100).dropWhile( i -> i % 10 < 5).limit(10).toArray()); assertEquals(100, IntStreamEx.range(100).dropWhile(i -> i % 10 < 0).count()); assertEquals(0, IntStreamEx.range(100).dropWhile(i -> i % 10 < 10).count()); assertEquals(OptionalInt.of(0), IntStreamEx.range(100).dropWhile(i -> i % 10 < 0).findFirst()); assertEquals(OptionalInt.empty(), IntStreamEx.range(100).dropWhile(i -> i % 10 < 10).findFirst()); java.util.Spliterator.OfInt spltr = IntStreamEx.range(100).dropWhile(i -> i % 10 < 1).spliterator(); assertTrue(spltr.tryAdvance((int x) -> assertEquals(1, x))); Builder builder = IntStream.builder(); spltr.forEachRemaining(builder); assertArrayEquals(IntStreamEx.range(2, 100).toArray(), builder.build().toArray()); }
@Test(expected = NullPointerException.class) public void parallelStreamWithNullBuilder() { ParallelIntStreamSupport.parallelStream((Builder) null, this.workerPool); }