This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push: new 418af7ee0 Reduce spurious failures seen on GitHub CI in org.apache.commons.lang3.ArrayUtilsTest methods that test ArrayUtils.shuffle() methods. 418af7ee0 is described below commit 418af7ee013f1ec9baff31aa948ee36e5790bc96 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sun Jul 20 11:42:47 2025 -0400 Reduce spurious failures seen on GitHub CI in org.apache.commons.lang3.ArrayUtilsTest methods that test ArrayUtils.shuffle() methods. --- src/changes/changes.xml | 1 + .../org/apache/commons/lang3/ArrayUtilsTest.java | 130 ++++++++++++++------- 2 files changed, 92 insertions(+), 39 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 28e633ea4..b04932dcb 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -53,6 +53,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Gary Gregory">[javadoc] Fix thrown exception documentation for org.apache.commons.lang3.reflect.MethodUtils.getMethodObject(Class<?>, String, Class<?>...).</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.lang3.reflect.MethodUtils.getMethodObject(Class<?>, String, Class<?>...) now returns null instead of throwing a NullPointerException, as it does for other exception types.</action> <action type="fix" dev="ggregory" due-to="Scott Parish">[javadoc] Strings::equalsAny: CI doc string should show it's insensitive #1416.</action> + <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> <!-- ADD --> <!-- UPDATE --> </release> diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java index cd2e31884..edd4af9b1 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java @@ -5196,38 +5196,34 @@ void testShiftShortArrayNull() { assertNull(array); } - @Test - void testShuffle() { - final String[] array1 = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; - final String[] array2 = ArrayUtils.clone(array1); - ArrayUtils.shuffle(array1); - assertFalse(Arrays.equals(array1, array2)); - for (final String element : array2) { - assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found"); - } - } - @Test void testShuffleBoolean() { - final boolean[] array1 = { true, false, true, true, false, false, true, false, false, true }; + // Don't use a "small" array to reduce spurious failures. + final boolean[] array1 = { true, false, true, true, false, false, true, false, false, true, true, false, true, true, false, false, true, false, false, + true, true, false, true, true, false, false, true, false, false, true, false, true, true, false, true, true, false, false, true, false, false, + false, true, true, false, false, true, false, false, true, false, true, true, false, true, true, false, false, true, false }; final boolean[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1); assertFalse(Arrays.equals(array1, array2)); - assertEquals(5, ArrayUtils.removeAllOccurrences(array1, true).length); } @Test void testShuffleBooleanRandom() { - final boolean[] array1 = { true, false, true, true, false, false, true, false, false, true }; + // Don't use a "small" array to reduce spurious failures. + final boolean[] array1 = { true, false, true, true, false, false, true, false, false, true, true, false, true, true, false, false, true, false, false, + true, true, false, true, true, false, false, true, false, false, true, false, true, true, false, true, true, false, false, true, false, false, + false, true, true, false, false, true, false, false, true, false, true, true, false, true, true, false, false, true, false }; final boolean[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); - assertEquals(5, ArrayUtils.removeAllOccurrences(array1, true).length); } @Test void testShuffleByte() { - final byte[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final byte[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1); assertFalse(Arrays.equals(array1, array2)); @@ -5238,7 +5234,10 @@ void testShuffleByte() { @Test void testShuffleByteRandom() { - final byte[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final byte[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); @@ -5249,7 +5248,10 @@ void testShuffleByteRandom() { @Test void testShuffleChar() { - final char[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final char[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1); assertFalse(Arrays.equals(array1, array2)); @@ -5260,7 +5262,10 @@ void testShuffleChar() { @Test void testShuffleCharRandom() { - final char[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final char[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); @@ -5271,7 +5276,10 @@ void testShuffleCharRandom() { @Test void testShuffleDouble() { - final double[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final double[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1); assertFalse(Arrays.equals(array1, array2)); @@ -5282,7 +5290,10 @@ void testShuffleDouble() { @Test void testShuffleDoubleRandom() { - final double[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final double[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); @@ -5293,7 +5304,10 @@ void testShuffleDoubleRandom() { @Test void testShuffleFloat() { - final float[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final float[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1); assertFalse(Arrays.equals(array1, array2)); @@ -5304,7 +5318,10 @@ void testShuffleFloat() { @Test void testShuffleFloatRandom() { - final float[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final float[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); @@ -5315,7 +5332,10 @@ void testShuffleFloatRandom() { @Test void testShuffleInt() { - final int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final int[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); @@ -5326,7 +5346,10 @@ void testShuffleInt() { @Test void testShuffleIntRandom() { - final int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final int[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1); assertFalse(Arrays.equals(array1, array2)); @@ -5337,7 +5360,10 @@ void testShuffleIntRandom() { @Test void testShuffleLong() { - final long[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final long[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1); assertFalse(Arrays.equals(array1, array2)); @@ -5348,7 +5374,10 @@ void testShuffleLong() { @Test void testShuffleLongRandom() { - final long[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final long[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); @@ -5358,21 +5387,27 @@ void testShuffleLongRandom() { } @Test - void testShuffleRandom() { - final String[] array1 = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; - final String[] array2 = ArrayUtils.clone(array1); - ArrayUtils.shuffle(array1, seededRandom()); + void testShuffleShort() { + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; + final short[] array2 = ArrayUtils.clone(array1); + ArrayUtils.shuffle(array1); assertFalse(Arrays.equals(array1, array2)); - for (final String element : array2) { + for (final short element : array2) { assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found"); } } @Test - void testShuffleShort() { - final short[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + void testShuffleShortRandom() { + // Don't use a "small" array, reduce spurious failures. + 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, + 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, + 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 }; final short[] array2 = ArrayUtils.clone(array1); - ArrayUtils.shuffle(array1); + ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); for (final short element : array2) { assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found"); @@ -5380,12 +5415,29 @@ void testShuffleShort() { } @Test - void testShuffleShortRandom() { - final short[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - final short[] array2 = ArrayUtils.clone(array1); + void testShuffleString() { + // Don't use a "small" array, reduce spurious failures. + 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", + "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", + "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; + final String[] array2 = ArrayUtils.clone(array1); + ArrayUtils.shuffle(array1); + assertFalse(Arrays.equals(array1, array2)); + for (final String element : array2) { + assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found"); + } + } + + @Test + void testShuffleStringRandom() { + // Don't use a "small" array, reduce spurious failures. + 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", + "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", + "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; + final String[] array2 = ArrayUtils.clone(array1); ArrayUtils.shuffle(array1, seededRandom()); assertFalse(Arrays.equals(array1, array2)); - for (final short element : array2) { + for (final String element : array2) { assertTrue(ArrayUtils.contains(array1, element), () -> "Element " + element + " not found"); } }