@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) public void testOps(String name, TestData.OfInt data) { long expectedCount = data.size(); withData(data). terminal(IntStream::count). expectedResult(expectedCount). exercise(); withData(data). terminal(s -> s.filter(e -> true), IntStream::count). expectedResult(expectedCount). exercise(); expectedCount = data.into(new HashSet<>()).size(); withData(data). terminal(IntStream::distinct, IntStream::count). expectedResult(expectedCount). exercise(); withData(data). terminal(s -> s.unordered().distinct(), IntStream::count). expectedResult(expectedCount). exercise(); }
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) public void testIntStream(String name, TestData.OfInt data) { for (IntPredicate p : INT_PREDICATES) { setContext("p", p); for (Kind kind : Kind.values()) { setContext("kind", kind); exerciseTerminalOps(data, intKinds.get(kind).apply(p)); exerciseTerminalOps(data, s -> s.filter(ipFalse), intKinds.get(kind).apply(p)); exerciseTerminalOps(data, s -> s.filter(ipEven), intKinds.get(kind).apply(p)); } } }
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) public void testOps(String name, TestData.OfInt data) { AtomicLong expectedCount = new AtomicLong(); data.stream().forEach(e -> expectedCount.incrementAndGet()); withData(data). terminal(IntStream::count). expectedResult(expectedCount.get()). exercise(); }
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) public void testOps(String name, TestData.OfInt data) { assertEquals(0, (int) exerciseTerminalOps(data, s -> s.filter(ipFalse), s -> s.reduce(0, irPlus))); OptionalInt seedless = exerciseTerminalOps(data, s -> s.reduce(irPlus)); int folded = exerciseTerminalOps(data, s -> s.reduce(0, irPlus)); assertEquals(folded, seedless.orElse(0)); seedless = exerciseTerminalOps(data, s -> s.reduce(irMin)); folded = exerciseTerminalOps(data, s -> s.reduce(Integer.MAX_VALUE, irMin)); assertEquals(folded, seedless.orElse(Integer.MAX_VALUE)); seedless = exerciseTerminalOps(data, s -> s.reduce(irMax)); folded = exerciseTerminalOps(data, s -> s.reduce(Integer.MIN_VALUE, irMax)); assertEquals(folded, seedless.orElse(Integer.MIN_VALUE)); seedless = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(irPlus)); folded = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(0, irPlus)); assertEquals(folded, seedless.orElse(0)); seedless = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(irMin)); folded = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(Integer.MAX_VALUE, irMin)); assertEquals(folded, seedless.orElse(Integer.MAX_VALUE)); seedless = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(irMax)); folded = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(Integer.MIN_VALUE, irMax)); assertEquals(folded, seedless.orElse(Integer.MIN_VALUE)); }
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) public void testIntOps(String name, TestData.OfInt data) { Collection<Integer> result = exerciseOps(data, s -> s.flatMap(i -> Collections.singleton(i).stream().mapToInt(j -> j))); assertEquals(data.size(), result.size()); assertContents(data, result); result = exerciseOps(data, s -> s.flatMap(i -> IntStream.empty())); assertEquals(0, result.size()); }
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) public void testIntSpliterators(String name, TestData.OfInt data) { for (Function<IntStream, IntStream> f : intStreamFunctions()) { SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.stream()).spliterator()); } }
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) public void testIntParSpliterators(String name, TestData.OfInt data) { for (Function<IntStream, IntStream> f : intStreamFunctions()) { SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.parallelStream()).spliterator()); } }
@Test(dataProvider = "IntStreamTestData.small", dataProviderClass = IntStreamTestDataProvider.class) public void testIntSpliterators(String name, TestData.OfInt data) { for (Function<IntStream, IntStream> f : intStreamFunctions()) { SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.stream()).spliterator()); } }
@Test(dataProvider = "IntStreamTestData.small", dataProviderClass = IntStreamTestDataProvider.class) public void testIntParSpliterators(String name, TestData.OfInt data) { for (Function<IntStream, IntStream> f : intStreamFunctions()) { SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.parallelStream()).spliterator()); } }
@Test(dataProvider = "IntStreamTestData.small", dataProviderClass = IntStreamTestDataProvider.class) public void testIntOpsX(String name, TestData.OfInt data) { exerciseOps(data, s -> s.flatMap(e -> IntStream.range(0, e))); exerciseOps(data, s -> s.flatMap(e -> IntStream.range(0, e).limit(10))); }