Merge branch 'feature-MATH-1339' into develop
Fixes the following issue (see JIRA): MATH-1339
This commit is contained in:
commit
73952558a1
|
@ -1617,8 +1617,7 @@ public class MathArrays {
|
|||
if (i == start) {
|
||||
target = start;
|
||||
} else {
|
||||
// NumberIsTooLargeException cannot occur.
|
||||
target = new UniformIntegerDistribution(start, i).createSampler(rng).sample();
|
||||
target = rng.nextInt(i - start + 1) + start;
|
||||
}
|
||||
final int temp = list[target];
|
||||
list[target] = list[i];
|
||||
|
@ -1632,8 +1631,7 @@ public class MathArrays {
|
|||
if (i == start) {
|
||||
target = start;
|
||||
} else {
|
||||
// NumberIsTooLargeException cannot occur.
|
||||
target = new UniformIntegerDistribution(i, start).createSampler(rng).sample();
|
||||
target = rng.nextInt(start - i + 1) + i;
|
||||
}
|
||||
final int temp = list[target];
|
||||
list[target] = list[i];
|
||||
|
|
|
@ -1107,6 +1107,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 };
|
||||
|
|
Loading…
Reference in New Issue