use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class IntervalTest method forEachWith.
@Test
public void forEachWith() {
IntegerSum sum = new IntegerSum(0);
Interval.oneTo(5).forEachWith((Integer each, Integer parameter) -> sum.add(each + parameter), 0);
Assert.assertEquals(15, sum.getIntSum());
IntegerSum sum2 = new IntegerSum(0);
Interval.fromTo(5, 1).forEachWith((Integer each, Integer parameter) -> sum2.add(each + parameter), 0);
Assert.assertEquals(15, sum2.getIntSum());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class DropIterableTest method forEach.
@Test
public void forEach() {
Sum sum1 = new IntegerSum(0);
this.dropIterable.forEach(new SumProcedure<>(sum1));
Assert.assertEquals(12, sum1.getValue().intValue());
Sum sum2 = new IntegerSum(0);
this.emptyListDropIterable.forEach(new SumProcedure<>(sum2));
Assert.assertEquals(0, sum2.getValue().intValue());
Sum sum3 = new IntegerSum(0);
this.zeroCountDropIterable.forEach(new SumProcedure<>(sum3));
Assert.assertEquals(15, sum3.getValue().intValue());
Sum sum5 = new IntegerSum(0);
this.nearCountDropIterable.forEach(new SumProcedure<>(sum5));
Assert.assertEquals(5, sum5.getValue().intValue());
Sum sum6 = new IntegerSum(0);
this.sameCountDropIterable.forEach(new SumProcedure<>(sum6));
Assert.assertEquals(0, sum6.getValue().intValue());
Sum sum7 = new IntegerSum(0);
this.higherCountDropIterable.forEach(new SumProcedure<>(sum7));
Assert.assertEquals(0, sum7.getValue().intValue());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class DropIterableTest method forEachWithIndex.
@Test
public void forEachWithIndex() {
Sum sum = new IntegerSum(0);
FastList<Integer> indices = FastList.newList(5);
ObjectIntProcedure<Integer> indexRecordingAndSumProcedure = (each, index) -> {
indices.add(index);
sum.add(each);
};
this.dropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0, 1, 2), indices);
Assert.assertEquals(12, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.emptyListDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.zeroCountDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0, 1, 2, 3, 4), indices);
Assert.assertEquals(15, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.nearCountDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0), indices);
Assert.assertEquals(5, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.sameCountDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.higherCountDropIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class DropWhileIterableTest method forEachWithIndex.
@Test
public void forEachWithIndex() {
Sum sum = new IntegerSum(0);
FastList<Integer> indices = FastList.newList(5);
ObjectIntProcedure<Integer> indexRecordingAndSumProcedure = (each, index) -> {
indices.add(index);
sum.add(each);
};
this.dropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0, 1, 2), indices);
Assert.assertEquals(12, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.emptyListDropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.alwaysFalseDropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0, 1, 2, 3, 4), indices);
Assert.assertEquals(15, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.mostlyFalseDropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(FastList.newListWith(0), indices);
Assert.assertEquals(5, sum.getValue().intValue());
indices.clear();
sum.add(sum.getValue().intValue() * -1);
this.alwaysTrueDropWhileIterable.forEachWithIndex(indexRecordingAndSumProcedure);
Assert.assertEquals(0, indices.size());
}
use of org.eclipse.collections.impl.math.IntegerSum in project eclipse-collections by eclipse.
the class DropWhileIterableTest method iterator.
@Override
@Test
public void iterator() {
Sum sum1 = new IntegerSum(0);
for (Integer each : this.dropWhileIterable) {
sum1.add(each);
}
Assert.assertEquals(12, sum1.getValue().intValue());
Sum sum2 = new IntegerSum(0);
for (Integer each : this.emptyListDropWhileIterable) {
sum2.add(each);
}
Assert.assertEquals(0, sum2.getValue().intValue());
Sum sum3 = new IntegerSum(0);
for (Integer each : this.alwaysFalseDropWhileIterable) {
sum3.add(each);
}
Assert.assertEquals(15, sum3.getValue().intValue());
Sum sum5 = new IntegerSum(0);
for (Integer each : this.mostlyFalseDropWhileIterable) {
sum5.add(each);
}
Assert.assertEquals(5, sum5.getValue().intValue());
Sum sum6 = new IntegerSum(0);
for (Integer each : this.alwaysTrueDropWhileIterable) {
sum6.add(each);
}
Assert.assertEquals(0, sum6.getValue().intValue());
}
Aggregations