use of com.annimon.stream.function.DoubleUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class IterateTest method testStreamIterateWithPredicate.
@Test
@SuppressWarnings("unchecked")
public void testStreamIterateWithPredicate() {
DoublePredicate condition = new DoublePredicate() {
@Override
public boolean test(double value) {
return value < 0.2;
}
};
DoubleUnaryOperator increment = new DoubleUnaryOperator() {
@Override
public double applyAsDouble(double t) {
return t + 0.05;
}
};
DoubleStream.iterate(0, condition, increment).custom(assertElements(arrayContaining(closeTo(0.00, 0.00001), closeTo(0.05, 0.00001), closeTo(0.10, 0.00001), closeTo(0.15, 0.00001))));
}
use of com.annimon.stream.function.DoubleUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class OptionalDoubleTest method testMap.
@Test
public void testMap() {
final DoubleUnaryOperator negatorFunction = new DoubleUnaryOperator() {
@Override
public double applyAsDouble(double operand) {
return -operand;
}
};
OptionalDouble result;
result = OptionalDouble.empty().map(negatorFunction);
assertThat(result, isEmpty());
result = OptionalDouble.of(10.123).map(negatorFunction);
assertThat(result, hasValueThat(closeTo(-10.123, 0.0001)));
}
use of com.annimon.stream.function.DoubleUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class IterateTest method testStreamIterate.
@Test
@SuppressWarnings("unchecked")
public void testStreamIterate() {
DoubleUnaryOperator operator = new DoubleUnaryOperator() {
@Override
public double applyAsDouble(double operand) {
return operand + 0.01;
}
};
DoubleStream.iterate(0.0, operator).limit(3).custom(assertElements(arrayContaining(closeTo(0.00, 0.00001), closeTo(0.01, 0.00001), closeTo(0.02, 0.00001))));
}
use of com.annimon.stream.function.DoubleUnaryOperator in project Lightweight-Stream-API by aNNiMON.
the class MapTest method testMap.
@Test
public void testMap() {
DoubleUnaryOperator negator = new DoubleUnaryOperator() {
@Override
public double applyAsDouble(double operand) {
return -operand;
}
};
DoubleStream.of(0.012, 3.039, 100d).map(negator).custom(assertElements(arrayContaining(-0.012, -3.039, -100d)));
DoubleStream.empty().map(negator).custom(assertIsEmpty());
}
Aggregations