This commit is contained in:
Looly 2024-07-05 18:18:24 +08:00
parent b2e5edb990
commit 6b60aef692
2 changed files with 11 additions and 4 deletions

View File

@ -1599,7 +1599,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
* @return 变更后的原数组
* @since 3.0.9
*/
public static <T> T[] reverse(final T[] array, final int startIndexInclusive, final int endIndexExclusive) {
public static <T> T[] reverse(final T[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (isEmpty(array)) {
return array;
}

View File

@ -21,8 +21,7 @@ import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.util.*;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link ArrayUtil} 数组工具单元测试
@ -555,7 +554,7 @@ public class ArrayUtilTest {
}
@Test
public void reverseTest2s() {
public void reverseTest2() {
final Object[] a = {"1", '2', "3", 4};
final Object[] reverse = ArrayUtil.reverse(a);
assertArrayEquals(new Object[]{4, "3", '2', "1"}, reverse);
@ -1071,4 +1070,12 @@ public class ArrayUtilTest {
assertEquals(5, resizedArray.length);
assertArrayEquals(new Integer[]{1, 2, 3, null, null}, resizedArray);
}
@Test
void testShuffleNotSameAsOriginal() {
final Integer[] initialArray = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
final Integer[] shuffledArray = ArrayUtil.shuffle(initialArray.clone());
assertNotEquals(Arrays.toString(initialArray), Arrays.toString(shuffledArray));
}
}