use of com.annimon.stream.function.DoublePredicate 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.DoublePredicate in project Lightweight-Stream-API by aNNiMON.
the class FilterNotTest method testFilterNot.
@Test
public void testFilterNot() {
final DoublePredicate predicate = Functions.greaterThan(Math.PI);
DoubleStream.of(0.012, 10.347, 3.039, 19.84, 100d).filterNot(predicate).custom(assertElements(arrayContaining(0.012, 3.039)));
DoubleStream.of(4.096, 12).filterNot(predicate).custom(assertIsEmpty());
}
use of com.annimon.stream.function.DoublePredicate in project Lightweight-Stream-API by aNNiMON.
the class FilterTest method testFilter.
@Test
public void testFilter() {
final DoublePredicate predicate = Functions.greaterThan(Math.PI);
DoubleStream.of(0.012, 10.347, 3.039, 19.84, 100d).filter(predicate).custom(assertElements(arrayContaining(10.347, 19.84, 100d)));
DoubleStream.of(0.012, -10).filter(predicate).custom(assertIsEmpty());
}
use of com.annimon.stream.function.DoublePredicate in project Lightweight-Stream-API by aNNiMON.
the class OnCloseTest method testOnCloseWithOtherOperators.
@Test
public void testOnCloseWithOtherOperators() {
final boolean[] state = new boolean[] { false };
DoubleStream stream = DoubleStream.of(0, 1, 2, 2, 3, 4, 4, 5).filter(new DoublePredicate() {
@Override
public boolean test(double value) {
return value < 4;
}
}).onClose(new Runnable() {
@Override
public void run() {
state[0] = true;
}
}).distinct().limit(2);
stream.findFirst();
stream.close();
assertTrue(state[0]);
}
Aggregations