use of com.annimon.stream.function.IntUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class FilterTest method testFilter.
@Test
public void testFilter() {
IntStream.rangeClosed(1, 10).filter(Functions.remainderInt(2)).custom(assertElements(arrayContaining(2, 4, 6, 8, 10)));
assertTrue(IntStream.iterate(0, new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return operand + 1;
}
}).filter(new IntPredicate() {
@Override
public boolean test(int value) {
return value == 0;
}
}).findFirst().getAsInt() == 0);
}
use of com.annimon.stream.function.IntUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class OptionalIntTest method testMap.
@Test
public void testMap() {
final IntUnaryOperator negatorFunction = new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return -operand;
}
};
OptionalInt result;
result = OptionalInt.empty().map(negatorFunction);
assertThat(result, isEmpty());
result = OptionalInt.of(10).map(negatorFunction);
assertThat(result, hasValue(-10));
}
use of com.annimon.stream.function.IntUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class SortedTest method testSorted.
@Test
public void testSorted() {
assertTrue(IntStream.empty().sorted().count() == 0);
assertTrue(IntStream.of(42).sorted().findFirst().getAsInt() == 42);
final boolean[] wrongOrder = new boolean[] { false };
IntStream.iterate(2, new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return -operand + 1;
}
}).limit(1000).sorted().forEach(new IntConsumer() {
int currentValue = Integer.MIN_VALUE;
@Override
public void accept(int value) {
if (value < currentValue) {
wrongOrder[0] = true;
}
currentValue = value;
}
});
assertTrue(!wrongOrder[0]);
}
use of com.annimon.stream.function.IntUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class IterateTest method testStreamIterateWithPredicate.
@Test
public void testStreamIterateWithPredicate() {
IntPredicate condition = new IntPredicate() {
@Override
public boolean test(int value) {
return value < 20;
}
};
IntUnaryOperator increment = new IntUnaryOperator() {
@Override
public int applyAsInt(int t) {
return t + 5;
}
};
IntStream.iterate(0, condition, increment).custom(assertElements(arrayContaining(0, 5, 10, 15)));
}
use of com.annimon.stream.function.IntUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class IterateTest method testStreamIterate.
@Test
public void testStreamIterate() {
IntUnaryOperator operator = new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return operand + 1;
}
};
assertTrue(IntStream.iterate(1, operator).limit(3).sum() == 6);
assertTrue(IntStream.iterate(1, operator).iterator().hasNext());
}
Aggregations