use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class AbstractImmutableSetTestCase method groupByEach.
@Test
public void groupByEach() {
ImmutableSet<Integer> undertest = this.classUnderTest();
NegativeIntervalFunction function = new NegativeIntervalFunction();
ImmutableSetMultimap<Integer, Integer> actual = undertest.groupByEach(function);
UnifiedSetMultimap<Integer, Integer> expected = UnifiedSet.newSet(undertest).groupByEach(function);
Assert.assertEquals(expected, actual);
}
use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class AbstractImmutableSortedBagTestCase method groupByEachWithTarget.
@Test
public void groupByEachWithTarget() {
ImmutableSortedBag<Integer> undertest = this.classUnderTest();
NegativeIntervalFunction function = new NegativeIntervalFunction();
TreeBagMultimap<Integer, Integer> actual = undertest.groupByEach(function, TreeBagMultimap.newMultimap());
TreeBagMultimap<Integer, Integer> expected = TreeBag.newBag(undertest).groupByEach(function);
Assert.assertEquals(expected, actual);
}
use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class AbstractMutableSortedBagTestCase method groupByEach.
@Override
@Test
public void groupByEach() {
super.groupByEach();
MutableSortedBag<Integer> bag = this.newWith(Collections.reverseOrder(), 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
NegativeIntervalFunction function = new NegativeIntervalFunction();
MutableSortedBagMultimap<Integer, Integer> expected = this.newWith(Collections.<Integer>reverseOrder()).groupByEach(function);
for (int i = 1; i < 10; i++) {
expected.putAll(-i, Interval.fromTo(i, 9));
}
expected.put(-1, 1);
expected.put(-1, 1);
MutableSortedBagMultimap<Integer, Integer> actual = bag.groupByEach(function);
Assert.assertEquals(expected, actual);
MutableSortedBagMultimap<Integer, Integer> actualWithTarget = bag.groupByEach(function, this.<Integer>newWith().groupByEach(function));
Assert.assertEquals(expected, actualWithTarget);
for (int i = 1; i < 10; ++i) {
Verify.assertSortedBagsEqual(expected.get(-i), actual.get(-i));
}
Verify.assertSize(9, actual.keysView().toList());
Verify.assertSize(9, actualWithTarget.keysView().toList());
}
use of org.eclipse.collections.impl.block.function.NegativeIntervalFunction in project eclipse-collections by eclipse.
the class ImmutableMemoryEfficientMapTestCase method groupByEach.
@Test
public void groupByEach() {
ImmutableMap<String, Integer> map = this.newMapWithKeysValues("1", 1, "2", 2, "3", 3, "4", 4);
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 DoubletonSetTest method groupByEach.
@Override
@Test
public void groupByEach() {
super.groupByEach();
MutableSet<Integer> set = Sets.fixedSize.of(1, 2);
MutableMultimap<Integer, Integer> expected = UnifiedSetMultimap.newMultimap();
set.forEach(Procedures.cast(value -> expected.putAll(-value, Interval.fromTo(value, set.size()))));
Multimap<Integer, Integer> actual = set.groupByEach(new NegativeIntervalFunction());
Assert.assertEquals(expected, actual);
Multimap<Integer, Integer> actualWithTarget = set.groupByEach(new NegativeIntervalFunction(), UnifiedSetMultimap.newMultimap());
Assert.assertEquals(expected, actualWithTarget);
}
Aggregations