use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class LazyIterateTest method rejectIterator.
@Test
public void rejectIterator() {
LazyIterable<Integer> select = LazyIterate.reject(Interval.oneTo(5), Predicates.lessThan(5));
Sum sum = new IntegerSum(0);
for (Integer each : select) {
sum.add(each);
}
Assert.assertEquals(5, sum.getValue().intValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class IterableIterateTest method injectIntoWithOver30.
@Test
public void injectIntoWithOver30() {
Sum result = new IntegerSum(0);
Integer parameter = 2;
List<Integer> integers = Interval.oneTo(31);
Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add((element.intValue() - element.intValue()) * withValue.intValue());
Sum sumOfDoubledValues = Iterate.injectIntoWith(result, integers, function, parameter);
Assert.assertEquals(0, sumOfDoubledValues.getValue().intValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class IntIntervalTest method forEachWithIndex.
@Test
public void forEachWithIndex() {
IntegerSum sum = new IntegerSum(0);
IntInterval.oneTo(5).forEachWithIndex((each, index) -> sum.add(each + index));
Assert.assertEquals(25, sum.getIntSum());
IntegerSum zeroSum = new IntegerSum(0);
IntInterval.fromTo(0, -4).forEachWithIndex((each, index) -> zeroSum.add(each + index));
Assert.assertEquals(0, zeroSum.getIntSum());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class MapIterableTestCase method injectInto.
@Test
public void injectInto() {
MapIterable<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);
Integer actual = map.injectInto(0, AddFunction.INTEGER);
Assert.assertEquals(Integer.valueOf(10), actual);
Sum sum = map.injectInto(new IntegerSum(0), SumProcedure.number());
Assert.assertEquals(new IntegerSum(10), sum);
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class FastListTest method testLazyRejectForEach.
/**
* @deprecated since 3.0. Use {@code asLazy().reject(Predicate)} instead.
*/
@Deprecated
@Test
public void testLazyRejectForEach() {
LazyIterable<Integer> select = FastList.newList(Interval.oneTo(5)).asLazy().reject(Predicates.lessThan(5));
Sum sum = new IntegerSum(0);
select.forEach(new SumProcedure<>(sum));
Assert.assertEquals(5, sum.getValue().intValue());
}
Aggregations