use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class DropWhileIterableTest method iterator.
@Override
@Test
public void iterator() {
Sum sum1 = new IntegerSum(0);
for (Integer each : this.dropWhileIterable) {
sum1.add(each);
}
Assert.assertEquals(12, sum1.getValue().intValue());
Sum sum2 = new IntegerSum(0);
for (Integer each : this.emptyListDropWhileIterable) {
sum2.add(each);
}
Assert.assertEquals(0, sum2.getValue().intValue());
Sum sum3 = new IntegerSum(0);
for (Integer each : this.alwaysFalseDropWhileIterable) {
sum3.add(each);
}
Assert.assertEquals(15, sum3.getValue().intValue());
Sum sum5 = new IntegerSum(0);
for (Integer each : this.mostlyFalseDropWhileIterable) {
sum5.add(each);
}
Assert.assertEquals(5, sum5.getValue().intValue());
Sum sum6 = new IntegerSum(0);
for (Integer each : this.alwaysTrueDropWhileIterable) {
sum6.add(each);
}
Assert.assertEquals(0, sum6.getValue().intValue());
}
use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class LazyIterableAdapterTest method forEachWithIndex.
@Test
public void forEachWithIndex() {
LazyIterable<Integer> select = new LazyIterableAdapter<>(Interval.oneTo(5));
Sum sum = new IntegerSum(0);
select.forEachWithIndex((object, index) -> {
sum.add(object);
sum.add(index);
LOGGER.info("value={} index={}", object, index);
});
Assert.assertEquals(25, sum.getValue().intValue());
}
use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class RejectIterableTest method forEachWith.
@Test
public void forEachWith() {
InternalIterable<Integer> select = new RejectIterable<>(Interval.oneTo(5), Predicates.lessThan(5));
Sum sum = new IntegerSum(0);
select.forEachWith((each, aSum) -> aSum.add(each), sum);
Assert.assertEquals(5, sum.getValue().intValue());
}
use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class RejectIterableTest method iterator.
@Override
@Test
public void iterator() {
InternalIterable<Integer> select = new RejectIterable<>(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.Sum in project eclipse-collections by eclipse.
the class SelectInstancesOfIterableTest method forEach.
@Test
public void forEach() {
InternalIterable<Integer> select = new SelectInstancesOfIterable<>(FastList.newListWith(1, 2.0, 3, 4.0, 5), Integer.class);
Sum sum = new IntegerSum(0);
select.forEach(new SumProcedure<>(sum));
Assert.assertEquals(9, sum.getValue().intValue());
}
Aggregations