Search in sources :

Example 16 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class TakeWhileIterableTest method iterator.

@Override
@Test
public void iterator() {
    Sum sum1 = new IntegerSum(0);
    for (Integer each : this.takeWhileIterable) {
        sum1.add(each);
    }
    Assert.assertEquals(3, sum1.getValue().intValue());
    Sum sum2 = new IntegerSum(0);
    for (Integer each : this.emptyListTakeWhileIterable) {
        sum2.add(each);
    }
    Assert.assertEquals(0, sum2.getValue().intValue());
    Sum sum3 = new IntegerSum(0);
    for (Integer each : this.alwaysFalseTakeWhileIterable) {
        sum3.add(each);
    }
    Assert.assertEquals(0, sum3.getValue().intValue());
    Sum sum5 = new IntegerSum(0);
    for (Integer each : this.alwaysTrueTakeWhileIterable) {
        sum5.add(each);
    }
    Assert.assertEquals(15, sum5.getValue().intValue());
}
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)

Example 17 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class ArrayListIterateTest method injectIntoWithOver100.

@Test
public void injectIntoWithOver100() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    Function3<Sum, Integer, Integer, Sum> function = (sum, element, withValue) -> sum.add((element.intValue() - element.intValue()) * withValue.intValue());
    Sum sumOfDoubledValues = ArrayListIterate.injectIntoWith(result, this.getOver100IntegerList(), function, parameter);
    Assert.assertEquals(0, sumOfDoubledValues.getValue().intValue());
}
Also used : Procedures2(org.eclipse.collections.impl.block.factory.Procedures2) Iterables.mList(org.eclipse.collections.impl.factory.Iterables.mList) HashingStrategies(org.eclipse.collections.impl.block.factory.HashingStrategies) Verify(org.eclipse.collections.impl.test.Verify) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) MutableBooleanList(org.eclipse.collections.api.list.primitive.MutableBooleanList) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) MutableFloatList(org.eclipse.collections.api.list.primitive.MutableFloatList) MutableShortList(org.eclipse.collections.api.list.primitive.MutableShortList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) Collection(java.util.Collection) Twin(org.eclipse.collections.api.tuple.Twin) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) List(java.util.List) ObjectIntProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure) MutableDoubleList(org.eclipse.collections.api.list.primitive.MutableDoubleList) MinSizeFunction(org.eclipse.collections.impl.block.function.MinSizeFunction) Iterables.iList(org.eclipse.collections.impl.factory.Iterables.iList) Lists(org.eclipse.collections.impl.factory.Lists) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Function(org.eclipse.collections.api.block.function.Function) Sum(org.eclipse.collections.impl.math.Sum) MutableByteList(org.eclipse.collections.api.list.primitive.MutableByteList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Function3(org.eclipse.collections.api.block.function.Function3) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) PartitionMutableList(org.eclipse.collections.api.partition.list.PartitionMutableList) Pair(org.eclipse.collections.api.tuple.Pair) PrimitiveFunctions(org.eclipse.collections.impl.block.factory.PrimitiveFunctions) Predicates(org.eclipse.collections.impl.block.factory.Predicates) MutableCharList(org.eclipse.collections.api.list.primitive.MutableCharList) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Test(org.junit.Test) MaxSizeFunction(org.eclipse.collections.impl.block.function.MaxSizeFunction) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) Assert(org.junit.Assert) Collections(java.util.Collections) 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)

Example 18 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class IterateTest method injectIntoWithRandomAccess.

@Test
public void injectIntoWithRandomAccess() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    MutableList<Integer> integers = Interval.oneTo(5).toList().asSynchronized();
    this.basicTestDoubleSum(result, integers, parameter);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) 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)

Example 19 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class IterateTest method injectIntoWith.

@Test
public void injectIntoWith() {
    Sum result = new IntegerSum(0);
    Integer parameter = 2;
    MutableList<Integer> integers = Interval.oneTo(5).toList();
    this.basicTestDoubleSum(result, integers, parameter);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BigInteger(java.math.BigInteger) 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)

Example 20 with Sum

use of org.eclipse.collections.impl.math.Sum in project eclipse-collections by eclipse.

the class IterateTest method forEachWith.

@Test
public void forEachWith() {
    this.iterables.each(each -> {
        Sum result = new IntegerSum(0);
        Iterate.forEachWith(each, (integer, parm) -> result.add(integer.intValue() * parm.intValue()), 2);
        Assert.assertEquals(30, result.getValue().intValue());
    });
}
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