Skip to content

Commit 418af7e

Browse files
committed
Reduce spurious failures seen on GitHub CI in
org.apache.commons.lang3.ArrayUtilsTest methods that test ArrayUtils.shuffle() methods.
1 parent f82dfcd commit 418af7e

File tree

2 files changed

+92
-39
lines changed

2 files changed

+92
-39
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The <action> type attribute can be add,update,fix,remove.
5353
<action type="fix" dev="ggregory" due-to="Gary Gregory">[javadoc] Fix thrown exception documentation for org.apache.commons.lang3.reflect.MethodUtils.getMethodObject(Class&lt;?&gt;, String, Class&lt;?&gt;...).</action>
5454
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.lang3.reflect.MethodUtils.getMethodObject(Class&lt;?&gt;, String, Class&lt;?&gt;...) now returns null instead of throwing a NullPointerException, as it does for other exception types.</action>
5555
<action type="fix" dev="ggregory" due-to="Scott Parish">[javadoc] Strings::equalsAny: CI doc string should show it's insensitive #1416.</action>
56+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Reduce spurious failures in org.apache.commons.lang3.ArrayUtilsTest methods that test ArrayUtils.shuffle() methods.</action>
5657
<!-- ADD -->
5758
<!-- UPDATE -->
5859
</release>

src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java

Lines changed: 91 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5196,38 +5196,34 @@ void testShiftShortArrayNull() {
51965196
assertNull(array);
51975197
}
51985198

5199-
@Test
5200-
void testShuffle() {
5201-
final String[] array1 = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
5202-
final String[] array2 = ArrayUtils.clone(array1);
5203-
ArrayUtils.shuffle(array1);
5204-
assertFalse(Arrays.equals(array1, array2));
5205-
for (final String element : array2) {
5206-
assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found");
5207-
}
5208-
}
5209-
52105199
@Test
52115200
void testShuffleBoolean() {
5212-
final boolean[] array1 = { true, false, true, true, false, false, true, false, false, true };
5201+
// Don't use a "small" array to reduce spurious failures.
5202+
final boolean[] array1 = { true, false, true, true, false, false, true, false, false, true, true, false, true, true, false, false, true, false, false,
5203+
true, true, false, true, true, false, false, true, false, false, true, false, true, true, false, true, true, false, false, true, false, false,
5204+
false, true, true, false, false, true, false, false, true, false, true, true, false, true, true, false, false, true, false };
52135205
final boolean[] array2 = ArrayUtils.clone(array1);
52145206
ArrayUtils.shuffle(array1);
52155207
assertFalse(Arrays.equals(array1, array2));
5216-
assertEquals(5, ArrayUtils.removeAllOccurrences(array1, true).length);
52175208
}
52185209

52195210
@Test
52205211
void testShuffleBooleanRandom() {
5221-
final boolean[] array1 = { true, false, true, true, false, false, true, false, false, true };
5212+
// Don't use a "small" array to reduce spurious failures.
5213+
final boolean[] array1 = { true, false, true, true, false, false, true, false, false, true, true, false, true, true, false, false, true, false, false,
5214+
true, true, false, true, true, false, false, true, false, false, true, false, true, true, false, true, true, false, false, true, false, false,
5215+
false, true, true, false, false, true, false, false, true, false, true, true, false, true, true, false, false, true, false };
52225216
final boolean[] array2 = ArrayUtils.clone(array1);
52235217
ArrayUtils.shuffle(array1, seededRandom());
52245218
assertFalse(Arrays.equals(array1, array2));
5225-
assertEquals(5, ArrayUtils.removeAllOccurrences(array1, true).length);
52265219
}
52275220

52285221
@Test
52295222
void testShuffleByte() {
5230-
final byte[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5223+
// Don't use a "small" array, reduce spurious failures.
5224+
final byte[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
5225+
3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
5226+
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
52315227
final byte[] array2 = ArrayUtils.clone(array1);
52325228
ArrayUtils.shuffle(array1);
52335229
assertFalse(Arrays.equals(array1, array2));
@@ -5238,7 +5234,10 @@ void testShuffleByte() {
52385234

52395235
@Test
52405236
void testShuffleByteRandom() {
5241-
final byte[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5237+
// Don't use a "small" array, reduce spurious failures.
5238+
final byte[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
5239+
3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
5240+
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
52425241
final byte[] array2 = ArrayUtils.clone(array1);
52435242
ArrayUtils.shuffle(array1, seededRandom());
52445243
assertFalse(Arrays.equals(array1, array2));
@@ -5249,7 +5248,10 @@ void testShuffleByteRandom() {
52495248

52505249
@Test
52515250
void testShuffleChar() {
5252-
final char[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5251+
// Don't use a "small" array, reduce spurious failures.
5252+
final char[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
5253+
3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
5254+
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
52535255
final char[] array2 = ArrayUtils.clone(array1);
52545256
ArrayUtils.shuffle(array1);
52555257
assertFalse(Arrays.equals(array1, array2));
@@ -5260,7 +5262,10 @@ void testShuffleChar() {
52605262

52615263
@Test
52625264
void testShuffleCharRandom() {
5263-
final char[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5265+
// Don't use a "small" array, reduce spurious failures.
5266+
final char[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
5267+
3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
5268+
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
52645269
final char[] array2 = ArrayUtils.clone(array1);
52655270
ArrayUtils.shuffle(array1, seededRandom());
52665271
assertFalse(Arrays.equals(array1, array2));
@@ -5271,7 +5276,10 @@ void testShuffleCharRandom() {
52715276

52725277
@Test
52735278
void testShuffleDouble() {
5274-
final double[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5279+
// Don't use a "small" array, reduce spurious failures.
5280+
final double[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
5281+
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
5282+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
52755283
final double[] array2 = ArrayUtils.clone(array1);
52765284
ArrayUtils.shuffle(array1);
52775285
assertFalse(Arrays.equals(array1, array2));
@@ -5282,7 +5290,10 @@ void testShuffleDouble() {
52825290

52835291
@Test
52845292
void testShuffleDoubleRandom() {
5285-
final double[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5293+
// Don't use a "small" array, reduce spurious failures.
5294+
final double[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
5295+
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
5296+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
52865297
final double[] array2 = ArrayUtils.clone(array1);
52875298
ArrayUtils.shuffle(array1, seededRandom());
52885299
assertFalse(Arrays.equals(array1, array2));
@@ -5293,7 +5304,10 @@ void testShuffleDoubleRandom() {
52935304

52945305
@Test
52955306
void testShuffleFloat() {
5296-
final float[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5307+
// Don't use a "small" array, reduce spurious failures.
5308+
final float[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
5309+
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
5310+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
52975311
final float[] array2 = ArrayUtils.clone(array1);
52985312
ArrayUtils.shuffle(array1);
52995313
assertFalse(Arrays.equals(array1, array2));
@@ -5304,7 +5318,10 @@ void testShuffleFloat() {
53045318

53055319
@Test
53065320
void testShuffleFloatRandom() {
5307-
final float[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5321+
// Don't use a "small" array, reduce spurious failures.
5322+
final float[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
5323+
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
5324+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
53085325
final float[] array2 = ArrayUtils.clone(array1);
53095326
ArrayUtils.shuffle(array1, seededRandom());
53105327
assertFalse(Arrays.equals(array1, array2));
@@ -5315,7 +5332,10 @@ void testShuffleFloatRandom() {
53155332

53165333
@Test
53175334
void testShuffleInt() {
5318-
final int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5335+
// Don't use a "small" array, reduce spurious failures.
5336+
final int[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
5337+
3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
5338+
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
53195339
final int[] array2 = ArrayUtils.clone(array1);
53205340
ArrayUtils.shuffle(array1, seededRandom());
53215341
assertFalse(Arrays.equals(array1, array2));
@@ -5326,7 +5346,10 @@ void testShuffleInt() {
53265346

53275347
@Test
53285348
void testShuffleIntRandom() {
5329-
final int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5349+
// Don't use a "small" array, reduce spurious failures.
5350+
final int[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
5351+
3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
5352+
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
53305353
final int[] array2 = ArrayUtils.clone(array1);
53315354
ArrayUtils.shuffle(array1);
53325355
assertFalse(Arrays.equals(array1, array2));
@@ -5337,7 +5360,10 @@ void testShuffleIntRandom() {
53375360

53385361
@Test
53395362
void testShuffleLong() {
5340-
final long[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5363+
// Don't use a "small" array, reduce spurious failures.
5364+
final long[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
5365+
3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
5366+
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
53415367
final long[] array2 = ArrayUtils.clone(array1);
53425368
ArrayUtils.shuffle(array1);
53435369
assertFalse(Arrays.equals(array1, array2));
@@ -5348,7 +5374,10 @@ void testShuffleLong() {
53485374

53495375
@Test
53505376
void testShuffleLongRandom() {
5351-
final long[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5377+
// Don't use a "small" array, reduce spurious failures.
5378+
final long[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
5379+
3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
5380+
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
53525381
final long[] array2 = ArrayUtils.clone(array1);
53535382
ArrayUtils.shuffle(array1, seededRandom());
53545383
assertFalse(Arrays.equals(array1, array2));
@@ -5358,34 +5387,57 @@ void testShuffleLongRandom() {
53585387
}
53595388

53605389
@Test
5361-
void testShuffleRandom() {
5362-
final String[] array1 = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
5363-
final String[] array2 = ArrayUtils.clone(array1);
5364-
ArrayUtils.shuffle(array1, seededRandom());
5390+
void testShuffleShort() {
5391+
// Don't use a "small" array, reduce spurious failures.
5392+
final short[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
5393+
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
5394+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
5395+
final short[] array2 = ArrayUtils.clone(array1);
5396+
ArrayUtils.shuffle(array1);
53655397
assertFalse(Arrays.equals(array1, array2));
5366-
for (final String element : array2) {
5398+
for (final short element : array2) {
53675399
assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found");
53685400
}
53695401
}
53705402

53715403
@Test
5372-
void testShuffleShort() {
5373-
final short[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5404+
void testShuffleShortRandom() {
5405+
// Don't use a "small" array, reduce spurious failures.
5406+
final short[] array1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
5407+
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
5408+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
53745409
final short[] array2 = ArrayUtils.clone(array1);
5375-
ArrayUtils.shuffle(array1);
5410+
ArrayUtils.shuffle(array1, seededRandom());
53765411
assertFalse(Arrays.equals(array1, array2));
53775412
for (final short element : array2) {
53785413
assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found");
53795414
}
53805415
}
53815416

53825417
@Test
5383-
void testShuffleShortRandom() {
5384-
final short[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5385-
final short[] array2 = ArrayUtils.clone(array1);
5418+
void testShuffleString() {
5419+
// Don't use a "small" array, reduce spurious failures.
5420+
final String[] array1 = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2",
5421+
"3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8",
5422+
"9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
5423+
final String[] array2 = ArrayUtils.clone(array1);
5424+
ArrayUtils.shuffle(array1);
5425+
assertFalse(Arrays.equals(array1, array2));
5426+
for (final String element : array2) {
5427+
assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found");
5428+
}
5429+
}
5430+
5431+
@Test
5432+
void testShuffleStringRandom() {
5433+
// Don't use a "small" array, reduce spurious failures.
5434+
final String[] array1 = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2",
5435+
"3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8",
5436+
"9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
5437+
final String[] array2 = ArrayUtils.clone(array1);
53865438
ArrayUtils.shuffle(array1, seededRandom());
53875439
assertFalse(Arrays.equals(array1, array2));
5388-
for (final short element : array2) {
5440+
for (final String element : array2) {
53895441
assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found");
53905442
}
53915443
}

0 commit comments

Comments
 (0)