use of com.annimon.stream.function.DoubleBinaryOperator in project Lightweight-Stream-API by aNNiMON.
the class ReduceTest method testReduceWithIdentity.
@Test
public void testReduceWithIdentity() {
double result = DoubleStream.of(0.012, -3.772, 3.039, 19.84, 100d).reduce(0d, new DoubleBinaryOperator() {
@Override
public double applyAsDouble(double left, double right) {
return left + right;
}
});
assertThat(result, closeTo(119.119, 0.0001));
}
use of com.annimon.stream.function.DoubleBinaryOperator in project Lightweight-Stream-API by aNNiMON.
the class CustomTest method testCustomIntermediateOperator_Zip.
@Test
@SuppressWarnings("unchecked")
public void testCustomIntermediateOperator_Zip() {
final DoubleBinaryOperator op = new DoubleBinaryOperator() {
@Override
public double applyAsDouble(double left, double right) {
return left * right;
}
};
DoubleStream s1 = DoubleStream.of(1.01, 2.02, 3.03);
IntStream s2 = IntStream.range(2, 5);
DoubleStream result = s1.custom(new CustomOperators.ZipWithIntStream(s2, op));
assertThat(result, elements(arrayContaining(closeTo(2.02, 0.00001), closeTo(6.06, 0.00001), closeTo(12.12, 0.00001))));
}
use of com.annimon.stream.function.DoubleBinaryOperator in project Lightweight-Stream-API by aNNiMON.
the class ReduceTest method testReduceWithIdentityOnEmptyStream.
@Test
public void testReduceWithIdentityOnEmptyStream() {
double result = DoubleStream.empty().reduce(Math.PI, new DoubleBinaryOperator() {
@Override
public double applyAsDouble(double left, double right) {
return left + right;
}
});
assertThat(result, closeTo(Math.PI, 0.00001));
}
Aggregations