mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
This commit is contained in:
@@ -363,7 +363,7 @@ public class ArrayUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void indexOfSubTest2(){
|
||||
public void indexOfSubTest2() {
|
||||
Integer[] a = {0x12, 0x56, 0x34, 0x56, 0x78, 0x9A};
|
||||
Integer[] b = {0x56, 0x78};
|
||||
int i = ArrayUtil.indexOfSub(a, b);
|
||||
@@ -401,7 +401,7 @@ public class ArrayUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastIndexOfSubTest2(){
|
||||
public void lastIndexOfSubTest2() {
|
||||
Integer[] a = {0x12, 0x56, 0x78, 0x56, 0x21, 0x9A};
|
||||
Integer[] b = {0x56, 0x78};
|
||||
int i = ArrayUtil.indexOfSub(a, b);
|
||||
@@ -409,17 +409,17 @@ public class ArrayUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverseTest(){
|
||||
int[] a = {1,2,3,4};
|
||||
public void reverseTest() {
|
||||
int[] a = {1, 2, 3, 4};
|
||||
final int[] reverse = ArrayUtil.reverse(a);
|
||||
Assert.assertArrayEquals(new int[]{4,3,2,1}, reverse);
|
||||
Assert.assertArrayEquals(new int[]{4, 3, 2, 1}, reverse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverseTest2s(){
|
||||
Object[] a = {"1",'2',"3",4};
|
||||
public void reverseTest2s() {
|
||||
Object[] a = {"1", '2', "3", 4};
|
||||
final Object[] reverse = ArrayUtil.reverse(a);
|
||||
Assert.assertArrayEquals(new Object[]{4,"3",'2',"1"}, reverse);
|
||||
Assert.assertArrayEquals(new Object[]{4, "3", '2', "1"}, reverse);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -461,9 +461,63 @@ public class ArrayUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTest(){
|
||||
public void getTest() {
|
||||
String[] a = {"a", "b", "c"};
|
||||
final Object o = ArrayUtil.get(a, -1);
|
||||
Assert.assertEquals("c", o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceTest() {
|
||||
String[] a = {"1", "2", "3", "4"};
|
||||
String[] b = {"a", "b", "c"};
|
||||
|
||||
// 在小于0的位置,-1位置插入,返回b+a
|
||||
String[] result = ArrayUtil.replace(a, -1, b);
|
||||
Assert.assertArrayEquals(new String[]{"a", "b", "c", "1", "2", "3", "4"}, result);
|
||||
|
||||
// 在第0个位置插入,即覆盖a,直接返回b
|
||||
result = ArrayUtil.replace(a, 0, b);
|
||||
Assert.assertArrayEquals(new String[]{"a", "b", "c"}, result);
|
||||
|
||||
// 在第1个位置插入,即"2"之前
|
||||
result = ArrayUtil.replace(a, 1, b);
|
||||
Assert.assertArrayEquals(new String[]{"1", "a", "b", "c"}, result);
|
||||
|
||||
//上一步测试修改了原数组结构
|
||||
String[] c = {"1", "2", "3", "4"};
|
||||
String[] d = {"a", "b", "c"};
|
||||
|
||||
// 在第2个位置插入,即"3"之后
|
||||
result = ArrayUtil.replace(c, 2, d);
|
||||
Assert.assertArrayEquals(new String[]{"1", "2", "a", "b", "c"}, result);
|
||||
|
||||
// 在第3个位置插入,即"4"之后
|
||||
result = ArrayUtil.replace(c, 3, d);
|
||||
Assert.assertArrayEquals(new String[]{"1", "2", "3", "a", "b", "c"}, result);
|
||||
|
||||
// 在第4个位置插入,数组长度为4,在索引4出替换即两个数组相加
|
||||
result = ArrayUtil.replace(c, 4, d);
|
||||
Assert.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result);
|
||||
|
||||
// 在大于3个位置插入,数组长度为4,即两个数组相加
|
||||
result = ArrayUtil.replace(c, 5, d);
|
||||
Assert.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result);
|
||||
|
||||
//上一步测试修改了原数组结构
|
||||
String[] e = null;
|
||||
String[] f = {"a", "b", "c"};
|
||||
|
||||
// e为null 返回 f
|
||||
result = ArrayUtil.replace(e, -1, f);
|
||||
Assert.assertArrayEquals(new String[]{"a", "b", "c"}, result);
|
||||
|
||||
//上一步测试修改了原数组结构
|
||||
String[] g = {"a", "b", "c"};
|
||||
String[] h = null;
|
||||
|
||||
// h为null 返回 g
|
||||
result = ArrayUtil.replace(g, 0, h);
|
||||
Assert.assertArrayEquals(new String[]{"a", "b", "c"}, result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user