add shuffle method
This commit is contained in:
@@ -7,6 +7,7 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -488,8 +489,37 @@ public class IntListTest {
|
||||
list.addAll(4, 2, 3, 1);
|
||||
list.sort();
|
||||
|
||||
final int[] expectedE = new int[] { 1, 2, 3, 4 };
|
||||
Assert.assertArrayEquals(expectedE, list.toArray());
|
||||
final int[] expected = new int[] { 1, 2, 3, 4 };
|
||||
Assert.assertArrayEquals(expected, list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortParallel() {
|
||||
final IntList list = new IntList();
|
||||
|
||||
list.addAll(4, 2, 3, 1);
|
||||
list.parallelSort();
|
||||
|
||||
final int[] expected = new int[] { 1, 2, 3, 4 };
|
||||
Assert.assertArrayEquals(expected, list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShuffle() {
|
||||
final IntList list = IntList.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final IntList original = list.clone();
|
||||
final IntList original2 = list.clone();
|
||||
|
||||
final Random random = new Random(1);
|
||||
list.shuffle(random);
|
||||
|
||||
Assert.assertEquals(original.size(), list.size());
|
||||
|
||||
original.removeAll(list);
|
||||
Assert.assertTrue("original minus shuffled list: " + original, original.isEmpty());
|
||||
|
||||
list.removeAll(original2);
|
||||
Assert.assertTrue("shuffled list minus original: " + list, list.isEmpty());
|
||||
}
|
||||
|
||||
private int[] removeElements(final int[] data, final int... removedIndices) {
|
||||
|
||||
Reference in New Issue
Block a user