add method removeIf

This commit is contained in:
2017-11-10 10:35:51 +01:00
parent b50cb8fdca
commit 88e0179dd5
3 changed files with 119 additions and 7 deletions

View File

@@ -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());
}
}