use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class SelectIterableTest method forEach.
@Test
public void forEach() {
InternalIterable<Integer> select = new SelectIterable<>(Interval.oneTo(5), Predicates.lessThan(5));
Sum sum = new IntegerSum(0);
select.forEach(new SumProcedure<>(sum));
Assert.assertEquals(10, sum.getValue().intValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class SelectIterableTest method forEachWithIndex.
@Test
public void forEachWithIndex() {
InternalIterable<Integer> select = new SelectIterable<>(Interval.oneTo(5), Predicates.lessThan(2).or(Predicates.greaterThan(3)));
Sum sum = new IntegerSum(0);
select.forEachWithIndex((object, index) -> {
sum.add(object);
sum.add(index);
LOGGER.info("value={} index={}", object, index);
});
Assert.assertEquals(13, sum.getValue().intValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class TakeWhileIterableTest method iterator.
@Override
@Test
public void iterator() {
Sum sum1 = new IntegerSum(0);
for (Integer each : this.takeWhileIterable) {
sum1.add(each);
}
Assert.assertEquals(3, sum1.getValue().intValue());
Sum sum2 = new IntegerSum(0);
for (Integer each : this.emptyListTakeWhileIterable) {
sum2.add(each);
}
Assert.assertEquals(0, sum2.getValue().intValue());
Sum sum3 = new IntegerSum(0);
for (Integer each : this.alwaysFalseTakeWhileIterable) {
sum3.add(each);
}
Assert.assertEquals(0, sum3.getValue().intValue());
Sum sum5 = new IntegerSum(0);
for (Integer each : this.alwaysTrueTakeWhileIterable) {
sum5.add(each);
}
Assert.assertEquals(15, sum5.getValue().intValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class ArrayListIterateTest method injectIntoWithOver100.
@Test
public void injectIntoWithOver100() {
Sum result = new IntegerSum(0);
Integer parameter = 2;
Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add((element.intValue() - element.intValue()) * withValue.intValue());
Sum sumOfDoubledValues = ArrayListIterate.injectIntoWith(result, this.getOver100IntegerList(), function, parameter);
Assert.assertEquals(0, sumOfDoubledValues.getValue().intValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class IterateTest method injectIntoWithRandomAccess.
@Test
public void injectIntoWithRandomAccess() {
Sum result = new IntegerSum(0);
Integer parameter = 2;
MutableList<Integer> integers = Interval.oneTo(5).toList().asSynchronized();
this.basicTestDoubleSum(result, integers, parameter);
}
Aggregations