use of java8.util.stream.IntStream in project streamsupport by stefan-zobel.
the class FindAnyOpTest method exerciseIntStream.
void exerciseIntStream(TestData.OfInt data, Function<IntStream, IntStream> fs) {
OptionalInt or = withData(data).terminal(fs, s -> s.findAny()).equalator(INT_VALID_ANSWER).exercise();
if (or.isPresent()) {
int r = or.getAsInt();
PrimitiveIterator.OfInt it = fs.apply(data.stream()).iterator();
boolean contained = false;
while (!contained && it.hasNext()) {
contained = r == it.nextInt();
}
assertTrue(contained);
} else {
assertFalse(fs.apply(data.stream()).iterator().hasNext());
}
}
use of java8.util.stream.IntStream in project streamsupport by stefan-zobel.
the class IntReduceTest method testOps.
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
public void testOps(String name, TestData.OfInt data) {
assertEquals(0, (int) exerciseTerminalOps(data, (IntStream 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, (IntStream s) -> s.map(irDoubler), s -> s.reduce(irPlus));
folded = exerciseTerminalOps(data, (IntStream s) -> s.map(irDoubler), s -> s.reduce(0, irPlus));
assertEquals(folded, seedless.orElse(0));
seedless = exerciseTerminalOps(data, (IntStream s) -> s.map(irDoubler), s -> s.reduce(irMin));
folded = exerciseTerminalOps(data, (IntStream s) -> s.map(irDoubler), s -> s.reduce(Integer.MAX_VALUE, irMin));
assertEquals(folded, seedless.orElse(Integer.MAX_VALUE));
seedless = exerciseTerminalOps(data, (IntStream s) -> s.map(irDoubler), s -> s.reduce(irMax));
folded = exerciseTerminalOps(data, (IntStream s) -> s.map(irDoubler), s -> s.reduce(Integer.MIN_VALUE, irMax));
assertEquals(folded, seedless.orElse(Integer.MIN_VALUE));
}
Aggregations