@Test public void testMapToDouble() { List<Rating> ratings = makeRatings(); double correct = ratings.stream() .mapToDouble(Rating::getValue) .sum(); double result = ObjectStreams.wrap(ratings) .mapToDouble(Rating::getValue) .sum(); assertThat(result, equalTo(correct)); }
@Test public void testMapToLong() { List<Rating> ratings = makeRatings(); long correct = ratings.stream() .mapToLong(Rating::getUserId) .sum(); long result = ObjectStreams.wrap(ratings) .mapToLong(Rating::getUserId) .sum(); assertThat(result, equalTo(correct)); }
@Test public void testFilter() { List<Rating> ratings = makeRatings(); List<Rating> correct = ratings.stream() .filter(r -> r.getUserId() % 2 == 1) .collect(Collectors.toList()); List<Rating> result = ObjectStreams.wrap(ratings) .filter(r -> r.getUserId() % 2 == 1) .collect(Collectors.toList()); assertThat(result, equalTo(correct)); }
@Test public void testMapToInt() { List<Rating> ratings = makeRatings(); int correct = ratings.stream() .mapToInt(r -> (int) r.getUserId()) .sum(); int result = ObjectStreams.wrap(ratings) .mapToInt(r -> (int) r.getUserId()) .sum(); assertThat(result, equalTo(correct)); }