Added some more tests for some of the new functions

This commit is contained in:
Speiger 2021-10-30 07:21:41 +02:00
parent c20c6393e5
commit 058087e15a
4 changed files with 50 additions and 0 deletions

View File

@ -118,6 +118,14 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
Assert.assertTrue(collection.removeAll(Arrays.asList(IntArrays.wrap(CONTAINS_ARRAY)))); Assert.assertTrue(collection.removeAll(Arrays.asList(IntArrays.wrap(CONTAINS_ARRAY))));
} }
@Test
public void testRemoveAllListener() {
if(!getValidCollectionTests().contains(CollectionTest.REMOVE_ALL_LISTENER)) return;
IntCollection collection = create(TEST_ARRAY);
Assert.assertTrue(collection.removeAll(create(CONTAINS_ARRAY), T -> {}));
Assert.assertFalse(collection.removeAll(create(CONTAINS_ARRAY), T -> Assert.assertTrue(false)));
}
@Test @Test
public void testRetainAll() { public void testRetainAll() {
if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL)) return; if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL)) return;
@ -135,6 +143,23 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
Assert.assertTrue(collection.isEmpty()); Assert.assertTrue(collection.isEmpty());
} }
@Test
public void testRetainAllListener() {
if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL_LISTENER)) return;
IntCollection collection = create(TEST_ARRAY);
IntCollection retained = create(CONTAINS_ARRAY);
Assert.assertTrue(collection.retainAll(retained, T -> {}));
Assert.assertFalse(collection.retainAll(retained, T -> Assert.assertTrue(false)));
Assert.assertEquals(CONTAINS_ARRAY.length, collection.size());
int[] retainedArray = retained.toIntArray();
int[] collectionArray = collection.toIntArray();
IntArrays.stableSort(retainedArray);
IntArrays.stableSort(collectionArray);
Assert.assertArrayEquals(retainedArray, collectionArray);
collection.retainAll(IntCollections.EMPTY, T -> {});
Assert.assertTrue(collection.isEmpty());
}
@Test @Test
public void testToArray() { public void testToArray() {
if(!getValidCollectionTests().contains(CollectionTest.TO_ARRAY)) return; if(!getValidCollectionTests().contains(CollectionTest.TO_ARRAY)) return;

View File

@ -64,6 +64,16 @@ public abstract class BaseIntListTest extends BaseIntCollectionTest
for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(i)); for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(i));
} }
@Test
public void testSpecialAdd() {
if(getValidListTests().contains(ListTest.ADD_SPECIAL)) return;
IntList list = create(TEST_ARRAY);
Assert.assertFalse(list.addIfAbsent(50));
Assert.assertTrue(list.addIfPresent(50));
Assert.assertTrue(list.addIfAbsent(150));
Assert.assertFalse(list.addIfAbsent(150));
}
@Test @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testIndex() { public void testIndex() {
@ -173,6 +183,17 @@ public abstract class BaseIntListTest extends BaseIntCollectionTest
} }
} }
@Test
public void testSwapRemove() {
if(getValidListTests().contains(ListTest.REMOVE_SWAP)) return;
IntList list = create(TEST_ARRAY);
Assert.assertEquals(TEST_ARRAY[50], list.swapRemove(50));
Assert.assertEquals(TEST_ARRAY[TEST_ARRAY.length-1], list.getInt(50));
list = create(TEST_ARRAY);
Assert.assertTrue(list.swapRemoveInt(50));
Assert.assertFalse(list.swapRemoveInt(50));
}
@Test @Test
public void testListIterator() { public void testListIterator() {
if(getValidListTests().contains(ListTest.LIST_ITERATOR)) return; if(getValidListTests().contains(ListTest.LIST_ITERATOR)) return;

View File

@ -11,7 +11,9 @@ public enum CollectionTest
REMOVE, REMOVE,
REMOVE_IF, REMOVE_IF,
REMOVE_ALL, REMOVE_ALL,
REMOVE_ALL_LISTENER,
RETAIN_ALL, RETAIN_ALL,
RETAIN_ALL_LISTENER,
TO_ARRAY, TO_ARRAY,
CLEAR, CLEAR,
WRAPPER, WRAPPER,

View File

@ -8,6 +8,7 @@ public enum ListTest
ADD_INDEX_COLLECTION, ADD_INDEX_COLLECTION,
ADD_INDEX_LIST, ADD_INDEX_LIST,
ADD_ELEMENTS, ADD_ELEMENTS,
ADD_SPECIAL,
INDEX, INDEX,
LAST_INDEX, LAST_INDEX,
GET, GET,
@ -17,6 +18,7 @@ public enum ListTest
SORT, SORT,
REPLACE, REPLACE,
REMOVE, REMOVE,
REMOVE_SWAP,
REMOVE_ELEMENTS, REMOVE_ELEMENTS,
EXTRACT_ELEMENTS, EXTRACT_ELEMENTS,
LIST_ITERATOR, LIST_ITERATOR,