use of com.annimon.stream.IntStream in project Lightweight-Stream-API by aNNiMON.
the class CustomTest method testCustomIntermediateOperator_Zip.
@Test
public void testCustomIntermediateOperator_Zip() {
final IntBinaryOperator op = new IntBinaryOperator() {
@Override
public int applyAsInt(int left, int right) {
return left + right;
}
};
IntStream s1 = IntStream.of(1, 3, 5, 7, 9);
IntStream s2 = IntStream.of(2, 4, 6, 8);
int[] expected = { 3, 7, 11, 15 };
IntStream result = s1.custom(new CustomOperators.Zip(s2, op));
assertThat(result.toArray(), is(expected));
}
use of com.annimon.stream.IntStream in project Lightweight-Stream-API by aNNiMON.
the class DistinctTest method testDistinctLazy.
@Test
public void testDistinctLazy() {
Integer[] expected = { 1, 2, 3, 5, -1 };
List<Integer> input = new ArrayList<Integer>();
input.addAll(Arrays.asList(1, 1, 2, 3, 5));
IntStream stream = Stream.of(input).mapToInt(Functions.toInt()).distinct();
input.addAll(Arrays.asList(3, 2, 1, 1, -1));
List<Integer> actual = stream.boxed().toList();
assertThat(actual, contains(expected));
}
use of com.annimon.stream.IntStream in project Lightweight-Stream-API by aNNiMON.
the class IntStreamMatcherTest method testElements.
@Test
public void testElements() {
final IntStream stream = IntStream.of(-813, 123456, Short.MAX_VALUE);
final Integer[] expected = new Integer[] { -813, 123456, (int) Short.MAX_VALUE };
final Matcher<IntStream> matcher = elements(arrayContaining(expected));
assertThat(stream, matcher);
assertTrue(matcher.matches(stream));
assertFalse(elements(arrayContaining(expected)).matches(IntStream.empty()));
assertThat(matcher, description(allOf(containsString("IntStream elements"), containsString(Stream.of(expected).map(new Function<Integer, String>() {
@Override
public String apply(Integer t) {
return String.format("<%s>", t.toString());
}
}).collect(Collectors.joining(", "))))));
}
Aggregations