use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class ImmutableUnifiedMapWithHashingStrategyTest 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.IntegerSum in project eclipse-collections by eclipse.
the class UnifiedMapWithHashingStrategyTest method batchForEachChains.
private void batchForEachChains(BatchIterable<Integer> batchIterable, int expectedValue) {
// Testing 1 batch with chains
Sum sum = new IntegerSum(0);
// testing getBatchCount returns 1
int numBatches = batchIterable.getBatchCount(100000);
for (int i = 0; i < numBatches; ++i) {
batchIterable.batchForEach(new SumProcedure<>(sum), i, numBatches);
}
Assert.assertEquals(1, numBatches);
Assert.assertEquals(expectedValue, sum.getValue());
// Testing 3 batches with chains and uneven last batch
Sum sum2 = new IntegerSum(0);
for (int i = 0; i < 5; ++i) {
batchIterable.batchForEach(new SumProcedure<>(sum2), i, 5);
}
Assert.assertEquals(expectedValue, sum2.getValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class UnifiedMapWithHashingStrategyTest method batchIterable_forEachEntry.
@Test
public void batchIterable_forEachEntry() {
BatchIterable<Map.Entry<Integer, Integer>> entries = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMapWithHashingStrategy.newWithKeysValues(INTEGER_HASHING_STRATEGY, 1, 1, 2, 2, 3, 3, 4, 4).entrySet();
Sum sum = new IntegerSum(0);
entries.forEach(new EntrySumProcedure(sum));
Assert.assertEquals(20, sum.getValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class UnifiedMapWithHashingStrategyTest method batchForEachEmptyBatchIterable.
private void batchForEachEmptyBatchIterable(BatchIterable<Integer> batchIterable) {
// Test batchForEach 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.IntegerSum in project eclipse-collections by eclipse.
the class UnifiedMapWithHashingStrategyTest method batchIterable_forEachEntry_chains.
@Test
public void batchIterable_forEachEntry_chains() {
BatchIterable<Map.Entry<Integer, Integer>> collisions = (BatchIterable<Map.Entry<Integer, Integer>>) UnifiedMapWithHashingStrategy.<Integer, Integer>newMap(INTEGER_HASHING_STRATEGY, 5).withKeysValues(COLLISION_1, 1, COLLISION_2, 2, COLLISION_3, 3, 1, 4).withKeysValues(2, 5, 3, 6).entrySet();
Sum sum = new IntegerSum(0);
collisions.forEach(new EntrySumProcedure(sum));
Assert.assertEquals(78, sum.getValue());
}
Aggregations