Added unit test.

This commit is contained in:
Gilles 2016-03-13 03:05:54 +01:00
parent 7a8dc00b8b
commit 808149305b
1 changed files with 17 additions and 0 deletions

View File

@ -1106,6 +1106,23 @@ public class MathArraysTest {
}
}
@Test
public void testShuffleNoDuplicates() {
final int n = 100;
final int[] orig = MathArrays.natural(n);
MathArrays.shuffle(orig);
// Test that all (unique) entries exist in the shuffled array.
final int[] count = new int[n];
for (int i = 0; i < n; i++) {
count[orig[i]] += 1;
}
for (int i = 0; i < n; i++) {
Assert.assertEquals(1, count[i]);
}
}
@Test
public void testShuffleTail() {
final int[] orig = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };