Beispiel #1
0
 public void testEveryMapShape() {
   assertCountSum(
       StreamSupport.stream(countTo(1000))
           .mapToInt(i -> i - 1)
           .mapToObj(i -> i + 1)
           .mapToLong(i -> i - 1)
           .mapToObj(i -> i + 1)
           .mapToDouble(i -> i - 1)
           .mapToObj(i -> i + 1)
           .mapToInt(i -> (int) (double) i)
           .mapToLong(i -> i)
           .mapToDouble(i -> i)
           .mapToLong(i -> (long) i)
           .mapToInt(i -> (int) i)
           .mapToObj(i -> i),
       1000,
       StreamSupport.stream(countTo(1000)).mapToInt(i -> i).sum());
 }
Beispiel #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));
  }