use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class UnifiedMapWithHashingStrategyTest method batchForEachEntry_emptySet.
@Test
public void batchForEachEntry_emptySet() {
// Test batchForEach on empty set, it should simply do nothing and not throw any exceptions
Sum sum5 = new IntegerSum(0);
BatchIterable<Map.Entry<Integer, Integer>> empty = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMapWithHashingStrategy.newMap(INTEGER_HASHING_STRATEGY).entrySet();
empty.batchForEach(new EntrySumProcedure(sum5), 0, empty.getBatchCount(1));
Assert.assertEquals(0, sum5.getValue());
}
use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class UnifiedMapWithHashingStrategyTest method batchForEachNullHandling.
private void batchForEachNullHandling(BatchIterable<Integer> batchIterable, int expectedValue) {
// Testing batchForEach handling null keys and null values
Sum sum = new IntegerSum(0);
for (int i = 0; i < batchIterable.getBatchCount(7); ++i) {
batchIterable.batchForEach(each -> sum.add(each == null ? 1 : each), i, batchIterable.getBatchCount(7));
}
Assert.assertEquals(expectedValue, sum.getValue());
}
use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class UnifiedMapWithHashingStrategyTest 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 AbstractMemoryEfficientMutableMapTest method injectInto.
@Test
public void injectInto() {
MutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3);
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;
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);
}
use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.
the class UnifiedMapTest method batchForEachTestCases.
private void batchForEachTestCases(BatchIterable<Integer> batchIterable, int expectedValue) {
// Testing batch size of 1 to 16 with no chains
for (int sectionCount = 1; sectionCount <= 16; ++sectionCount) {
Sum sum = new IntegerSum(0);
for (int sectionIndex = 0; sectionIndex < sectionCount; ++sectionIndex) {
batchIterable.batchForEach(new SumProcedure<>(sum), sectionIndex, sectionCount);
}
Assert.assertEquals(expectedValue, sum.getValue());
}
}
Aggregations