use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class ImmutableHashBagTest method groupByEach.
@Override
@Test
public void groupByEach() {
ImmutableBag<Integer> immutableBag = ImmutableHashBag.newBagWith(1, 2, 2, 3, 3, 3, 4, 4, 4, 4);
MutableMultimap<Integer, Integer> expected = HashBagMultimap.newMultimap();
int keys = this.numKeys();
immutableBag.forEachWithOccurrences((each, parameter) -> {
HashBag<Integer> bag = HashBag.newBag();
Interval.fromTo(each, keys).forEach((int eachInt) -> bag.addOccurrences(eachInt, eachInt));
expected.putAll(-each, bag);
});
Multimap<Integer, Integer> actual = immutableBag.groupByEach(new NegativeIntervalFunction());
Assert.assertEquals(expected, actual);
Multimap<Integer, Integer> actualWithTarget = immutableBag.groupByEach(new NegativeIntervalFunction(), HashBagMultimap.newMultimap());
Assert.assertEquals(expected, actualWithTarget);
}
use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class ArrayIterateTest method groupByEach.
@Test
public void groupByEach() {
MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
for (int i = 1; i < 8; i++) {
expected.putAll(-i, Interval.fromTo(i, 7));
}
Multimap<Integer, Integer> actual = ArrayIterate.groupByEach(new Integer[] { 1, 2, 3, 4, 5, 6, 7 }, new NegativeIntervalFunction());
Assert.assertEquals(expected, actual);
}
use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class MapIterableTestCase method groupByEach.
@Test
public void groupByEach() {
MapIterable<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);
MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
for (int i = 1; i < 4; i++) {
expected.putAll(-i, Interval.fromTo(i, 4));
}
NegativeIntervalFunction function = new NegativeIntervalFunction();
Multimap<Integer, Integer> actual = map.groupByEach(function);
expected.forEachKey(each -> {
Assert.assertTrue(actual.containsKey(each));
MutableList<Integer> values = actual.get(each).toList();
Verify.assertNotEmpty(values);
Assert.assertTrue(expected.get(each).containsAllIterable(values));
});
Multimap<Integer, Integer> actualFromTarget = map.groupByEach(function, FastListMultimap.newMultimap());
expected.forEachKey(each -> {
Assert.assertTrue(actualFromTarget.containsKey(each));
MutableList<Integer> values = actualFromTarget.get(each).toList();
Verify.assertNotEmpty(values);
Assert.assertTrue(expected.get(each).containsAllIterable(values));
});
}
use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class AbstractMemoryEfficientMutableMapTest method groupByEach.
@Test
public void groupByEach() {
MutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3);
MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
for (int i = 1; i < map.size(); i++) {
expected.putAll(-i, Interval.fromTo(i, map.size()));
}
NegativeIntervalFunction function = new NegativeIntervalFunction();
Multimap<Integer, Integer> actual = map.groupByEach(function);
expected.forEachKey(each -> {
Assert.assertTrue(actual.containsKey(each));
MutableList<Integer> values = actual.get(each).toList();
Verify.assertNotEmpty(values);
Assert.assertTrue(expected.get(each).containsAllIterable(values));
});
Multimap<Integer, Integer> actualFromTarget = map.groupByEach(function, FastListMultimap.newMultimap());
expected.forEachKey(each -> {
Assert.assertTrue(actualFromTarget.containsKey(each));
MutableList<Integer> values = actualFromTarget.get(each).toList();
Verify.assertNotEmpty(values);
Assert.assertTrue(expected.get(each).containsAllIterable(values));
});
}
use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class SynchronizedMutableCollectionTest method groupByEach.
@Override
@Test
public void groupByEach() {
RichIterable<Integer> underTest = this.newWith(1, 2, 3, 4, 5, 6, 7);
MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
for (int i = 1; i < 8; i++) {
expected.putAll(-i, Interval.fromTo(i, 7));
}
Multimap<Integer, Integer> actual = underTest.groupByEach(new NegativeIntervalFunction());
Assert.assertEquals(expected, actual);
Multimap<Integer, Integer> actualWithTarget = underTest.groupByEach(new NegativeIntervalFunction(), FastListMultimap.newMultimap());
Assert.assertEquals(expected, actualWithTarget);
}
Aggregations