mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add test
This commit is contained in:
@@ -1152,7 +1152,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
|
|||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region ----- indexOf and lastIndexOf and contains
|
// region ----- indexOf and lastIndexOf
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回数组中指定元素所在位置,未找到返回{@link #INDEX_NOT_FOUND}
|
* 返回数组中指定元素所在位置,未找到返回{@link #INDEX_NOT_FOUND}
|
||||||
|
@@ -163,12 +163,60 @@ public class ArrayUtilTest {
|
|||||||
public void containsAllTest() {
|
public void containsAllTest() {
|
||||||
final Integer[] a = {1, 2, 3, 4, 3, 6};
|
final Integer[] a = {1, 2, 3, 4, 3, 6};
|
||||||
boolean contains = ArrayUtil.containsAll(a, 4, 2, 6);
|
boolean contains = ArrayUtil.containsAll(a, 4, 2, 6);
|
||||||
|
// 提供的可变参数中元素顺序不需要一致
|
||||||
Assertions.assertTrue(contains);
|
Assertions.assertTrue(contains);
|
||||||
|
|
||||||
contains = ArrayUtil.containsAll(a, 1, 2, 3, 5);
|
contains = ArrayUtil.containsAll(a, 1, 2, 3, 5);
|
||||||
Assertions.assertFalse(contains);
|
Assertions.assertFalse(contains);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void containsIgnoreCaseTest() {
|
||||||
|
final String[] keys = {"a", "B", "c"};
|
||||||
|
final boolean b = ArrayUtil.containsIgnoreCase(keys, "b");
|
||||||
|
Assertions.assertTrue(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContainsIgnoreCaseWithEmptyArray() {
|
||||||
|
final CharSequence[] array = new CharSequence[0];
|
||||||
|
final CharSequence value = "test";
|
||||||
|
final boolean result = ArrayUtil.containsIgnoreCase(array, value);
|
||||||
|
Assertions.assertFalse(result, "Expected the result to be false for an empty array.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContainsIgnoreCaseWithNullValue() {
|
||||||
|
final CharSequence[] array = {"Hello", "World"};
|
||||||
|
final CharSequence value = null;
|
||||||
|
final boolean result = ArrayUtil.containsIgnoreCase(array, value);
|
||||||
|
Assertions.assertFalse(result, "Expected the result to be false when the value is null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContainsIgnoreCaseWithExistingValue() {
|
||||||
|
final CharSequence[] array = {"Hello", "World"};
|
||||||
|
final CharSequence value = "world";
|
||||||
|
final boolean result = ArrayUtil.containsIgnoreCase(array, value);
|
||||||
|
Assertions.assertTrue(result, "Expected the result to be true when the value exists in the array.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContainsIgnoreCaseWithNonExistingValue() {
|
||||||
|
final CharSequence[] array = {"Hello", "World"};
|
||||||
|
final CharSequence value = "Java";
|
||||||
|
final boolean result = ArrayUtil.containsIgnoreCase(array, value);
|
||||||
|
Assertions.assertFalse(result, "Expected the result to be false when the value does not exist in the array.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContainsIgnoreCaseWithCaseSensitiveValue() {
|
||||||
|
final CharSequence[] array = {"Hello", "World"};
|
||||||
|
final CharSequence value = "HELLO";
|
||||||
|
final boolean result = ArrayUtil.containsIgnoreCase(array, value);
|
||||||
|
Assertions.assertTrue(result, "Expected the result to be true when the value exists in the array with different case sensitivity.");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void zipTest() {
|
public void zipTest() {
|
||||||
final String[] keys = {"a", "b", "c"};
|
final String[] keys = {"a", "b", "c"};
|
||||||
@@ -525,6 +573,13 @@ public class ArrayUtilTest {
|
|||||||
Assertions.assertEquals("c", o);
|
Assertions.assertEquals("c", o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getByPredicateTest() {
|
||||||
|
final String[] a = {"a", "b", "c"};
|
||||||
|
final Object o = ArrayUtil.get(a, "b"::equals);
|
||||||
|
Assertions.assertEquals("b", o);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void replaceTest() {
|
public void replaceTest() {
|
||||||
final String[] a = {"1", "2", "3", "4"};
|
final String[] a = {"1", "2", "3", "4"};
|
||||||
|
Reference in New Issue
Block a user