mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add test
This commit is contained in:
@@ -561,6 +561,20 @@ public class ArrayUtilTest {
|
||||
assertArrayEquals(new Object[]{4, "3", '2', "1"}, reverse);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveWithValidIndex() {
|
||||
final String[] array = {"a", "b", "c", "d"};
|
||||
final String[] result = ArrayUtil.remove(array, 1);
|
||||
assertArrayEquals(new String[]{"a", "c", "d"}, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveEleFromObjectArray() {
|
||||
final Integer[] array = {1, 2, 3, 2, 4};
|
||||
final Integer[] expected = {1, 3, 2, 4};
|
||||
Assertions.assertArrayEquals(expected, ArrayUtil.removeEle(array, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeEmptyTest() {
|
||||
final String[] a = {"a", "b", "", null, " ", "c"};
|
||||
@@ -643,7 +657,7 @@ public class ArrayUtilTest {
|
||||
final String[] a = {"1", "2", "3", "4"};
|
||||
final String[] b = {"a", "b", "c"};
|
||||
|
||||
// 在小于0的位置,-1的位置插入,返回b+a,新数组
|
||||
// 在小于0的位置,相当于在a前插入b,返回b+a,新数组
|
||||
String[] result = ArrayUtil.replace(a, -1, b);
|
||||
assertArrayEquals(new String[]{"a", "b", "c", "1", "2", "3", "4"}, result);
|
||||
|
||||
@@ -1035,4 +1049,26 @@ public class ArrayUtilTest {
|
||||
// Then
|
||||
assertArrayEquals(list.toArray(new String[0]), result, "The array should match the list contents.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResizeWithSmallerSize() {
|
||||
// Setup
|
||||
final Integer[] originalArray = {1, 2, 3, 4, 5};
|
||||
// Execute
|
||||
final Integer[] resizedArray = ArrayUtil.resize(originalArray, 3);
|
||||
// Assert
|
||||
assertEquals(3, resizedArray.length);
|
||||
assertArrayEquals(new Integer[]{1, 2, 3}, resizedArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResizeWithLargerSize() {
|
||||
// Setup
|
||||
final Integer[] originalArray = {1, 2, 3};
|
||||
// Execute
|
||||
final Integer[] resizedArray = ArrayUtil.resize(originalArray, 5);
|
||||
// Assert
|
||||
assertEquals(5, resizedArray.length);
|
||||
assertArrayEquals(new Integer[]{1, 2, 3, null, null}, resizedArray);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user