use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class UnifiedMapTest method batchIterable_forEachEmptyBatchIterable.
private void batchIterable_forEachEmptyBatchIterable(BatchIterable<Integer> batchIterable) {
// Test forEach on empty set, it should simply do nothing and not throw any exceptions
Sum sum = new IntegerSum(0);
batchIterable.batchForEach(new SumProcedure<>(sum), 0, batchIterable.getBatchCount(1));
Assert.assertEquals(0, sum.getValue());
}
use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class ImmutableUnifiedMapTest method batchForEach.
@Test
public void batchForEach() {
Sum sum = new IntegerSum(0);
BatchIterable<String> integerBatchIterable = (BatchIterable<String>) this.classUnderTest();
integerBatchIterable.batchForEach(each -> sum.add(Integer.valueOf(each)), 0, 1);
Assert.assertEquals(10, sum.getValue());
}
use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class ImmutableMemoryEfficientMapTestCase method injectInto.
@Test
public void injectInto() {
ImmutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);
Integer expectedInteger;
IntegerSum expectedSum;
switch(map.size()) {
case 1:
expectedSum = new IntegerSum(1);
expectedInteger = Integer.valueOf(1);
break;
case 2:
expectedSum = new IntegerSum(3);
expectedInteger = Integer.valueOf(3);
break;
case 3:
expectedSum = new IntegerSum(6);
expectedInteger = Integer.valueOf(6);
break;
case 4:
expectedSum = new IntegerSum(10);
expectedInteger = Integer.valueOf(10);
break;
default:
expectedSum = new IntegerSum(0);
expectedInteger = Integer.valueOf(0);
break;
}
Integer actual = map.injectInto(0, AddFunction.INTEGER);
Assert.assertEquals(expectedInteger, actual);
Sum sum = map.injectInto(new IntegerSum(0), SumProcedure.number());
Assert.assertEquals(expectedSum, sum);
}
Aggregations