@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) public void testOps(String name, TestData.OfLong data) { long expectedCount = data.size(); withData(data). terminal(LongStream::count). expectedResult(expectedCount). exercise(); withData(data). terminal(s -> s.filter(e -> true), LongStream::count). expectedResult(expectedCount). exercise(); expectedCount = data.into(new HashSet<>()).size(); withData(data). terminal(LongStream::distinct, LongStream::count). expectedResult(expectedCount). exercise(); withData(data). terminal(s -> s.unordered().distinct(), LongStream::count). expectedResult(expectedCount). exercise(); }
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) public void testLongStream(String name, TestData.OfLong data) { for (LongPredicate p : LONG_PREDICATES) { setContext("p", p); for (Kind kind : Kind.values()) { setContext("kind", kind); exerciseTerminalOps(data, longKinds.get(kind).apply(p)); exerciseTerminalOps(data, s -> s.filter(lpFalse), longKinds.get(kind).apply(p)); exerciseTerminalOps(data, s -> s.filter(lpEven), longKinds.get(kind).apply(p)); } } }
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) public void testOps(String name, TestData.OfLong data) { AtomicLong expectedCount = new AtomicLong(); data.stream().forEach(e -> expectedCount.incrementAndGet()); withData(data). terminal(LongStream::count). expectedResult(expectedCount.get()). exercise(); }
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) public void testLongOps(String name, TestData.OfLong data) { Collection<Long> result = exerciseOps(data, s -> s.flatMap(i -> Collections.singleton(i).stream().mapToLong(j -> j))); assertEquals(data.size(), result.size()); assertContents(data, result); result = exerciseOps(data, s -> LongStream.empty()); assertEquals(0, result.size()); }
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) public void testLongSpliterators(String name, TestData.OfLong data) { for (Function<LongStream, LongStream> f : longStreamFunctions()) { SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.stream()).spliterator()); } }
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) public void testLongParSpliterators(String name, TestData.OfLong data) { for (Function<LongStream, LongStream> f : longStreamFunctions()) { SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.parallelStream()).spliterator()); } }
@Test(dataProvider = "LongStreamTestData.small", dataProviderClass = LongStreamTestDataProvider.class) public void testLongSpliterators(String name, TestData.OfLong data) { for (Function<LongStream, LongStream> f : longStreamFunctions()) { SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.stream()).spliterator()); } }
@Test(dataProvider = "LongStreamTestData.small", dataProviderClass = LongStreamTestDataProvider.class) public void testLongParSpliterators(String name, TestData.OfLong data) { for (Function<LongStream, LongStream> f : longStreamFunctions()) { SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.parallelStream()).spliterator()); } }
@Test(dataProvider = "LongStreamTestData.small", dataProviderClass = LongStreamTestDataProvider.class) public void testLongOpsX(String name, TestData.OfLong data) { exerciseOps(data, s -> s.flatMap(e -> LongStream.range(0, e))); exerciseOps(data, s -> s.flatMap(e -> LongStream.range(0, e).limit(10))); }