use of org.eclipse.collections.api.list.ImmutableList in project eclipse-collections by eclipse.
the class AbstractImmutableListTestCase method groupByEach.
@Test
public void groupByEach() {
ImmutableList<Integer> list = this.classUnderTest();
MutableMultimap<Integer, Integer> expected = FastListMultimap.newMultimap();
list.forEach(Procedures.cast(value -> expected.putAll(-value, Interval.fromTo(value, list.size()))));
Multimap<Integer, Integer> actual = list.groupByEach(new NegativeIntervalFunction());
Assert.assertEquals(expected, actual);
Multimap<Integer, Integer> actualWithTarget = list.groupByEach(new NegativeIntervalFunction(), FastListMultimap.newMultimap());
Assert.assertEquals(expected, actualWithTarget);
}
use of org.eclipse.collections.api.list.ImmutableList in project eclipse-collections by eclipse.
the class MutableListTestCase method MutableList_shuffleThis.
@Test
default void MutableList_shuffleThis() {
Integer[] integers = Interval.oneTo(50).toArray();
MutableList<Integer> mutableList1 = this.newWith(integers);
MutableList<Integer> mutableList2 = this.newWith(integers);
Collections.shuffle(mutableList1, new Random(10));
assertEquals(mutableList1, mutableList2.shuffleThis(new Random(10)));
MutableList<Integer> list = this.newWith(1, 2, 3);
UnifiedSet<ImmutableList<Integer>> objects = UnifiedSet.newSet();
while (objects.size() < 6) {
objects.add(list.shuffleThis().toImmutable());
}
Interval interval = Interval.oneTo(1000);
MutableList<Integer> bigList = this.newWith(interval.toArray());
MutableList<Integer> shuffledBigList = bigList.shuffleThis(new Random(8));
MutableList<Integer> integers1 = this.newWith(interval.toArray());
assertEquals(integers1.shuffleThis(new Random(8)), bigList);
assertSame(bigList, shuffledBigList);
assertSame(bigList, bigList.shuffleThis());
assertSame(bigList, bigList.shuffleThis(new Random(8)));
assertEquals(interval.toBag(), bigList.toBag());
}
Aggregations