Search in sources :

Example 6 with IntStream

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());
    }
}
Also used : PrimitiveIterator(java8.util.PrimitiveIterator) OptionalInt(java8.util.OptionalInt)

Example 7 with IntStream

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));
}
Also used : LambdaTestHelpers(java8.util.stream.LambdaTestHelpers) J8Arrays(java8.util.J8Arrays) IntStream(java8.util.stream.IntStream) OpTestCase(java8.util.stream.OpTestCase) Test(org.testng.annotations.Test) OptionalInt(java8.util.OptionalInt) IntStreamTestDataProvider(java8.util.stream.IntStreamTestDataProvider) TestData(java8.util.stream.TestData) IntStreams(java8.util.stream.IntStreams) OptionalInt(java8.util.OptionalInt) IntStream(java8.util.stream.IntStream) Test(org.testng.annotations.Test)

Aggregations

IntStream (java8.util.stream.IntStream)6 OpTestCase (java8.util.stream.OpTestCase)5 Test (org.testng.annotations.Test)5 List (java.util.List)4 Function (java8.util.function.Function)4 DoubleStream (java8.util.stream.DoubleStream)4 IntStreams (java8.util.stream.IntStreams)4 LongStream (java8.util.stream.LongStream)4 TestData (java8.util.stream.TestData)4 Consumer (java8.util.function.Consumer)3 LambdaTestHelpers (java8.util.stream.LambdaTestHelpers)3 RefStreams (java8.util.stream.RefStreams)3 Stream (java8.util.stream.Stream)3 StreamSupport (java8.util.stream.StreamSupport)3 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 OptionalInt (java8.util.OptionalInt)2