Example #1
0
 @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
 public void testOps(String name, TestData.OfRef<Integer> data) {
   exerciseOpsInt(
       data, s -> s.map(mId), s -> s.map(e -> e), s -> s.map(e -> e), s -> s.map(e -> e));
   exerciseOpsInt(
       data, s -> s.map(mZero), s -> s.map(e -> 0), s -> s.map(e -> 0), s -> s.map(e -> 0));
   exerciseOpsInt(
       data,
       s -> s.map(mDoubler),
       s -> s.map(e -> 2 * e),
       s -> s.map(e -> 2 * e),
       s -> s.map(e -> 2 * e));
   exerciseOpsInt(
       data,
       s -> s.map(LambdaTestHelpers.compose(mId, mDoubler)),
       s -> s.map(e -> 2 * e),
       s -> s.map(e -> 2 * e),
       s -> s.map(e -> 2 * e));
   exerciseOpsInt(
       data,
       s -> s.map(LambdaTestHelpers.compose(mDoubler, mDoubler)),
       s -> s.map(e -> 4 * e),
       s -> s.map(e -> 4 * e),
       s -> s.map(e -> 4 * e));
   exerciseOps(data, s -> s.mapToInt(i -> i));
   exerciseOps(data, s -> s.mapToLong(i -> i));
   exerciseOps(data, s -> s.mapToDouble(i -> i));
 }
Example #2
0
  public void testMap() {
    assertCountSum(StreamSupport.stream(countTo(0)).map(mId), 0, 0);
    assertCountSum(StreamSupport.stream(countTo(10)).map(mId), 10, 55);
    assertCountSum(StreamSupport.stream(countTo(10)).map(mZero), 10, 0);
    assertCountSum(StreamSupport.stream(countTo(0)).map(mDoubler), 0, 0);
    assertCountSum(StreamSupport.stream(countTo(10)).map(mDoubler), 10, 110);
    assertCountSum(StreamSupport.stream(countTo(10)).map(mDoubler).map(mDoubler), 10, 220);

    exerciseOps(countTo(0), s -> s.map(LambdaTestHelpers.identity()), countTo(0));
    exerciseOps(countTo(1000), s -> s.map(LambdaTestHelpers.identity()), countTo(1000));
    // @@@ Force cast to integer so output is Stream<Integer> rather an IntStream
    //     this just ensures that no warnings are logged about boxing
    //     when the result is compared with the output
    exerciseOps(countTo(1000), s -> s.map(e -> (Integer) (1000 + e)), range(1001, 2000));
  }