Search in sources :

Example 86 with Sum

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());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum)

Example 87 with Sum

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());
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) BatchIterable(org.eclipse.collections.impl.parallel.BatchIterable) Test(org.junit.Test)

Example 88 with Sum

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);
}
Also used : IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Sum(org.eclipse.collections.impl.math.Sum) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) Test(org.junit.Test)

Aggregations

IntegerSum (org.eclipse.collections.impl.math.IntegerSum)88 Sum (org.eclipse.collections.impl.math.Sum)88 Test (org.junit.Test)76 BatchIterable (org.eclipse.collections.impl.parallel.BatchIterable)20 MutableMap (org.eclipse.collections.api.map.MutableMap)17 Map (java.util.Map)16 Interval (org.eclipse.collections.impl.list.Interval)10 FastList (org.eclipse.collections.impl.list.mutable.FastList)10 UnifiedMap (org.eclipse.collections.impl.map.mutable.UnifiedMap)10 Assert (org.junit.Assert)10 ObjectIntProcedure (org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure)9 HashMap (java.util.HashMap)8 ImmutableEntry (org.eclipse.collections.impl.tuple.ImmutableEntry)8 Procedure2 (org.eclipse.collections.api.block.procedure.Procedure2)7 Predicates (org.eclipse.collections.impl.block.factory.Predicates)7 Before (org.junit.Before)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 LazyIterable (org.eclipse.collections.api.LazyIterable)6 Verify (org.eclipse.collections.impl.test.Verify)6 BigInteger (java.math.BigInteger)5