add method removeIf
This commit is contained in:
@@ -692,4 +692,49 @@ public class IntListTest {
|
||||
Assert.assertArrayEquals(new int[] {}, list.toArray());
|
||||
Assert.assertArrayEquals(new int[] {}, retain.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveIf() {
|
||||
final IntList list = IntList.of(1, 2, 3, 4, 5, 6);
|
||||
|
||||
list.removeIf(i -> i % 2 == 0);
|
||||
Assert.assertArrayEquals(new int[] { 1, 3, 5 }, list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveIfNegationOfPredicate() {
|
||||
final IntList list = IntList.of(1, 2, 3, 4, 5, 6);
|
||||
|
||||
final IntPredicate predicate = i -> i % 2 == 0;
|
||||
list.removeIf(predicate.negate());
|
||||
Assert.assertArrayEquals(new int[] { 2, 4, 6 }, list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveIfWithAndCombinedPredicates() {
|
||||
final IntList list = IntList.of(1, 2, 3, 4, 5, 6);
|
||||
|
||||
final IntPredicate predicateA = i -> i % 2 == 0;
|
||||
final IntPredicate predicateB = i -> i == 3 || i == 4;
|
||||
list.removeIf(predicateA.and(predicateB));
|
||||
Assert.assertArrayEquals(new int[] { 1, 2, 3, 5, 6 }, list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveIfWithOrCombinedPredicates() {
|
||||
final IntList list = IntList.of(1, 2, 3, 4, 5, 6);
|
||||
|
||||
final IntPredicate predicateA = i -> i % 2 == 0;
|
||||
final IntPredicate predicateB = i -> i == 3 || i == 4;
|
||||
list.removeIf(predicateA.or(predicateB));
|
||||
Assert.assertArrayEquals(new int[] { 1, 5 }, list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveIfOnEmptyList() {
|
||||
final IntList list = IntList.of();
|
||||
|
||||
list.removeIf(i -> false);
|
||||
Assert.assertArrayEquals(new int[] {}, list.toArray());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user