Adding First set of UnitTest
-Fixed: bugs in ArrayList implementation. -Added: Unit Tests for the following interfaces: Iterable/Collection/List -Added: ArrayList Test -Fixed: QuickSort was broken. -Added: Shuffle method. -Added: Shared random to SanityChecks
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.collections.IntCollection;
|
||||
import speiger.src.collections.ints.utils.IntArrays;
|
||||
import speiger.src.collections.ints.utils.IntCollections;
|
||||
import speiger.src.collections.ints.utils.IntCollections.SynchronizedCollection;
|
||||
import speiger.src.collections.ints.utils.IntCollections.UnmodifiableCollection;
|
||||
import speiger.src.collections.tests.CollectionTest;
|
||||
|
||||
public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
||||
{
|
||||
protected static final int[] ADD_ARRAY = new int[]{3212, -12, 423, -182, -4912};
|
||||
protected static final int[] CONTAINS_ARRAY = new int[]{23, 45, 63, 89, 32};
|
||||
|
||||
@Override
|
||||
protected abstract IntCollection create(int[] data);
|
||||
|
||||
protected EnumSet<CollectionTest> getValidCollectionTests() { return EnumSet.allOf(CollectionTest.class); }
|
||||
|
||||
@Test
|
||||
public void testAdd() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.ADD)) return;
|
||||
IntCollection collection = create(TEST_EMPTY);
|
||||
Assert.assertTrue(collection.isEmpty());
|
||||
collection.add(2012);
|
||||
Assert.assertFalse(collection.isEmpty());
|
||||
Assert.assertTrue(collection.contains(2012));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAll() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.ADD_ALL)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertEquals(TEST_ARRAY.length, collection.size());
|
||||
collection.addAll(create(ADD_ARRAY));
|
||||
Assert.assertEquals(TEST_ARRAY.length + ADD_ARRAY.length, collection.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testContains() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.CONTAINS)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertTrue(collection.contains(50));
|
||||
Assert.assertFalse(collection.contains(5120));
|
||||
Assert.assertTrue(collection.contains(Integer.valueOf(50)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsAll() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.CONTAINS_ALL)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertTrue(create(CONTAINS_ARRAY).containsAll(collection));
|
||||
Assert.assertFalse(create(ADD_ARRAY).containsAll(collection));
|
||||
Assert.assertTrue(collection.containsAll(Arrays.asList(IntArrays.wrap(TEST_ARRAY))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testContainsAny() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.CONTAINS_ANY)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertTrue(collection.containsAny(create(CONTAINS_ARRAY)));
|
||||
Assert.assertFalse(collection.containsAny(create(ADD_ARRAY)));
|
||||
Assert.assertTrue(collection.containsAny(Arrays.asList(IntArrays.wrap(CONTAINS_ARRAY))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testRemove() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.REMOVE)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertTrue(collection.remInt(50));
|
||||
Assert.assertFalse(collection.remInt(50));
|
||||
Assert.assertTrue(collection.remove(Integer.valueOf(75)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testRemoveIf() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.REMOVE_IF)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertTrue(collection.remIf(T -> T != 25));
|
||||
Assert.assertFalse(collection.remIf(T -> T != 25));
|
||||
Assert.assertEquals(1, collection.size());
|
||||
collection = create(TEST_ARRAY);
|
||||
Assert.assertTrue(collection.removeIf(T -> T.intValue() != 25));
|
||||
Assert.assertFalse(collection.removeIf(T -> T.intValue() != 25));
|
||||
Assert.assertEquals(1, collection.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAll() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.REMOVE_ALL)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertTrue(collection.removeAll(create(CONTAINS_ARRAY)));
|
||||
Assert.assertFalse(collection.removeAll(create(CONTAINS_ARRAY)));
|
||||
collection = create(TEST_ARRAY);
|
||||
Assert.assertFalse(collection.removeAll(Arrays.asList(IntArrays.wrap(ADD_ARRAY))));
|
||||
Assert.assertTrue(collection.removeAll(Arrays.asList(IntArrays.wrap(CONTAINS_ARRAY))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
IntCollection retained = create(CONTAINS_ARRAY);
|
||||
Assert.assertTrue(collection.retainAll(retained));
|
||||
Assert.assertFalse(collection.retainAll(retained));
|
||||
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);
|
||||
Assert.assertTrue(collection.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToArray() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.TO_ARRAY)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
int[] array = collection.toIntArray();
|
||||
IntArrays.stableSort(array);
|
||||
Assert.assertTrue(Arrays.equals(TEST_ARRAY, array));
|
||||
int[] other = collection.toIntArray(new int[collection.size()]);
|
||||
IntArrays.stableSort(other);
|
||||
Assert.assertTrue(Arrays.equals(TEST_ARRAY, other));
|
||||
Assert.assertTrue(Arrays.equals(TEST_ARRAY, IntArrays.unwrap(collection.toArray(new Integer[collection.size()]))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.CLEAR)) return;
|
||||
IntCollection collection = create(TEST_ARRAY);
|
||||
Assert.assertFalse(collection.isEmpty());
|
||||
collection.clear();
|
||||
Assert.assertTrue(collection.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
if(!getValidCollectionTests().contains(CollectionTest.WRAPPER)) return;
|
||||
IntCollection collection = create(TEST_EMPTY);
|
||||
collection = IntCollections.synchronizedCollection(collection);
|
||||
Assert.assertTrue(collection instanceof SynchronizedCollection);
|
||||
collection = IntCollections.unmodifiableCollection(collection);
|
||||
Assert.assertTrue(collection instanceof UnmodifiableCollection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.collections.IntIterable;
|
||||
import speiger.src.collections.ints.collections.IntIterator;
|
||||
import speiger.src.collections.tests.IterableTest;
|
||||
|
||||
public abstract class BaseIntIterableTest
|
||||
{
|
||||
protected static final int[] TEST_EMPTY = new int[0];
|
||||
protected static final int[] TEST_ARRAY = IntStream.range(0, 100).toArray();
|
||||
|
||||
protected abstract IntIterable create(int[] data);
|
||||
|
||||
protected EnumSet<IterableTest> getValidIterableTests() { return EnumSet.allOf(IterableTest.class); }
|
||||
|
||||
@Test
|
||||
public void testForEach() {
|
||||
if(getValidIterableTests().contains(IterableTest.FOR_EACH)) {
|
||||
create(TEST_ARRAY).forEach(T -> Assert.assertTrue(T >= 0 && T < 100));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIteratorForEach() {
|
||||
if(getValidIterableTests().contains(IterableTest.ITERATOR_FOR_EACH)) {
|
||||
create(TEST_ARRAY).iterator().forEachRemaining(T -> Assert.assertTrue(T >= 0 && T < 100));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkip() {
|
||||
if(getValidIterableTests().contains(IterableTest.ITERATOR_SKIP)) {
|
||||
IntIterator iter = create(TEST_ARRAY).iterator();
|
||||
Assert.assertEquals(50, iter.skip(50));
|
||||
Assert.assertNotEquals(100, iter.skip(100));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIteratorLoop() {
|
||||
if(getValidIterableTests().contains(IterableTest.ITERATOR_LOOP)) {
|
||||
for(int entry : create(TEST_ARRAY)) Assert.assertTrue(entry >= 0 && entry < 100);
|
||||
|
||||
for(IntIterator iter = create(TEST_ARRAY).iterator();iter.hasNext();) {
|
||||
int entry = iter.nextInt();
|
||||
Assert.assertTrue(entry >= 0 && entry < 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIteratorRemovalLoop() {
|
||||
if(getValidIterableTests().contains(IterableTest.ITERATOR_REMOVAL)) {
|
||||
for(IntIterator iter = create(TEST_ARRAY).iterator();iter.hasNext();) {
|
||||
int entry = iter.nextInt();
|
||||
Assert.assertTrue(entry >= 0 && entry < 100);
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
import speiger.src.collections.ints.lists.IntListIterator;
|
||||
import speiger.src.collections.ints.utils.IntCollections;
|
||||
import speiger.src.collections.tests.ListTest;
|
||||
|
||||
public abstract class BaseIntListTest extends BaseIntCollectionTest
|
||||
{
|
||||
@Override
|
||||
protected abstract IntList create(int[] data);
|
||||
protected EnumSet<ListTest> getValidListTests() { return EnumSet.allOf(ListTest.class); }
|
||||
|
||||
@Test
|
||||
public void testAddIndex() {
|
||||
if(getValidListTests().contains(ListTest.ADD_INDEX)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
list.add(50, -10);
|
||||
Assert.assertEquals(TEST_ARRAY.length+1, list.size());
|
||||
Assert.assertEquals(-10, list.getInt(50));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddList() {
|
||||
if(getValidListTests().contains(ListTest.ADD_LIST)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
IntList adding = create(ADD_ARRAY);
|
||||
list.addAll(adding);
|
||||
for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(TEST_ARRAY.length + i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddIndexCollection() {
|
||||
if(getValidListTests().contains(ListTest.ADD_INDEX_COLLECTION)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
IntList adding = create(ADD_ARRAY);
|
||||
list.addAll(0, IntCollections.unmodifiableCollection(adding));
|
||||
for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddIndexList() {
|
||||
if(getValidListTests().contains(ListTest.ADD_INDEX_LIST)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
IntList adding = create(ADD_ARRAY);
|
||||
list.addAll(adding);
|
||||
for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(TEST_ARRAY.length + i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddElements() {
|
||||
if(getValidListTests().contains(ListTest.ADD_ELEMENTS)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
IntList adding = create(ADD_ARRAY);
|
||||
list.addAll(0, adding);
|
||||
for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testIndex() {
|
||||
if(getValidListTests().contains(ListTest.INDEX)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
Assert.assertEquals(50, list.indexOf(50));
|
||||
Assert.assertEquals(25, list.indexOf(25));
|
||||
Assert.assertEquals(75, list.indexOf(75));
|
||||
Assert.assertEquals(50, list.indexOf(Integer.valueOf(50)));
|
||||
Assert.assertEquals(25, list.indexOf(Integer.valueOf(25)));
|
||||
Assert.assertEquals(75, list.indexOf(Integer.valueOf(75)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testLastIndex() {
|
||||
if(getValidListTests().contains(ListTest.LAST_INDEX)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
Assert.assertEquals(50, list.lastIndexOf(50));
|
||||
Assert.assertEquals(25, list.lastIndexOf(25));
|
||||
Assert.assertEquals(75, list.lastIndexOf(75));
|
||||
Assert.assertEquals(50, list.lastIndexOf(Integer.valueOf(50)));
|
||||
Assert.assertEquals(25, list.lastIndexOf(Integer.valueOf(25)));
|
||||
Assert.assertEquals(75, list.lastIndexOf(Integer.valueOf(75)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet() {
|
||||
if(getValidListTests().contains(ListTest.GET)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
for(int i = 0;i<list.size();i++) Assert.assertEquals(TEST_ARRAY[i], list.getInt(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetElements() {
|
||||
if(getValidListTests().contains(ListTest.GET_ELEMENTS)) return;
|
||||
int[] elements = create(TEST_ARRAY).extractElements(25, 75);
|
||||
for(int i = 0;i<elements.length;i++) Assert.assertEquals(TEST_ARRAY[i+25], elements[i]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSet() {
|
||||
if(getValidListTests().contains(ListTest.SET)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
Assert.assertEquals(25, list.set(25, -124));
|
||||
Assert.assertEquals(-124, list.getInt(25));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReSize() {
|
||||
if(getValidListTests().contains(ListTest.RE_SIZE)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
Assert.assertEquals(TEST_ARRAY.length, list.size());
|
||||
list.size(25);
|
||||
Assert.assertEquals(25, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSort() {
|
||||
if(getValidListTests().contains(ListTest.SORT)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
Collections.shuffle(list);
|
||||
Assert.assertFalse(Arrays.equals(TEST_ARRAY, list.toIntArray()));
|
||||
list.sort(null);
|
||||
Assert.assertArrayEquals(TEST_ARRAY, list.toIntArray());
|
||||
Collections.shuffle(list);
|
||||
Assert.assertFalse(Arrays.equals(TEST_ARRAY, list.toIntArray()));
|
||||
list.unstableSort(null);
|
||||
Assert.assertArrayEquals(TEST_ARRAY, list.toIntArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplace() {
|
||||
if(getValidListTests().contains(ListTest.REPLACE)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
for(int i = 0;i<list.size();i++) Assert.assertEquals(TEST_ARRAY[i], list.getInt(i));
|
||||
list.replaceInts(T -> 99 - T);
|
||||
for(int i = 0;i<list.size();i++) Assert.assertEquals(TEST_ARRAY[TEST_ARRAY.length - i - 1], list.getInt(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListRemove() {
|
||||
if(getValidListTests().contains(ListTest.REMOVE)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
list.remInt(50);
|
||||
Assert.assertEquals(TEST_ARRAY.length - 1, list.size());
|
||||
Assert.assertFalse(list.contains(50));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveElements() {
|
||||
if(getValidListTests().contains(ListTest.REMOVE_ELEMENTS)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
list.removeElements(25, 75);
|
||||
Assert.assertEquals(TEST_ARRAY.length - 50, list.size());
|
||||
for(int i = 0;i<50;i++) Assert.assertEquals(TEST_ARRAY[i + (i < 25 ? 0 : 50)], list.getInt(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractElements() {
|
||||
if(getValidListTests().contains(ListTest.EXTRACT_ELEMENTS)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
int[] elements = list.extractElements(25, 75);
|
||||
for(int i = 0;i<elements.length;i++) {
|
||||
Assert.assertEquals(TEST_ARRAY[i + 25], elements[i]);
|
||||
Assert.assertEquals(TEST_ARRAY[i + (i < 25 ? 0 : 50)], list.getInt(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListIterator() {
|
||||
if(getValidListTests().contains(ListTest.LIST_ITERATOR)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
IntListIterator iter = list.listIterator(50);
|
||||
iter.nextInt();
|
||||
iter.set(-250);
|
||||
iter.nextInt();
|
||||
iter.add(50);
|
||||
Assert.assertEquals(-250, list.getInt(50));
|
||||
Assert.assertEquals(50, list.getInt(51));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubList() {
|
||||
if(getValidListTests().contains(ListTest.SUB_LIST)) return;
|
||||
IntList list = create(TEST_ARRAY);
|
||||
IntList subList = list.subList(25, 75);
|
||||
Assert.assertEquals(50, subList.size());
|
||||
for(int i = 0;i<subList.size();i++) Assert.assertEquals(TEST_ARRAY[i + 25], subList.getInt(i));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.utils.IIntArray;
|
||||
|
||||
public interface IIntArrayTest
|
||||
{
|
||||
static final int[] TEST_ARRAY = IntStream.range(0, 100).toArray();
|
||||
public IIntArray create(int[] data);
|
||||
|
||||
@Test
|
||||
public default void testEnsureCapacity()
|
||||
{
|
||||
IIntArray array = create(TEST_ARRAY);
|
||||
array.ensureCapacity(2500);
|
||||
Assert.assertTrue(array.elements().length >= 2500);
|
||||
}
|
||||
|
||||
@Test
|
||||
public default void testElements()
|
||||
{
|
||||
IIntArray array = create(TEST_ARRAY);
|
||||
Assert.assertArrayEquals(TEST_ARRAY, array.elements());
|
||||
array.elements(T -> Assert.assertArrayEquals(TEST_ARRAY, T));
|
||||
}
|
||||
|
||||
@Test
|
||||
public default void testTrim()
|
||||
{
|
||||
IIntArray array = create(TEST_ARRAY);
|
||||
array.ensureCapacity(2500);
|
||||
Assert.assertNotEquals(TEST_ARRAY.length, array.elements().length);
|
||||
array.trim();
|
||||
Assert.assertEquals(TEST_ARRAY.length, array.elements().length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package speiger.src.collections.ints.base;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.collections.IntStack;
|
||||
|
||||
public interface IIntStackTests
|
||||
{
|
||||
static final int[] TEST_ARRAY = IntStream.range(0, 100).toArray();
|
||||
|
||||
public IntStack create(int[] data);
|
||||
|
||||
@Test
|
||||
public default void testPush()
|
||||
{
|
||||
IntStack stacks = create(TEST_ARRAY);
|
||||
stacks.pushInt(500);
|
||||
Assert.assertEquals(500, stacks.topInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public default void testPop()
|
||||
{
|
||||
Assert.assertEquals(99, create(TEST_ARRAY).topInt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package speiger.src.collections.ints.lists;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseIntListTest;
|
||||
import speiger.src.collections.ints.base.IIntArrayTest;
|
||||
import speiger.src.collections.ints.base.IIntStackTests;
|
||||
|
||||
public class IntArrayListTest extends BaseIntListTest implements IIntStackTests, IIntArrayTest
|
||||
{
|
||||
@Override
|
||||
public IntArrayList create(int[] data) {
|
||||
return new IntArrayList(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testPush() {
|
||||
IIntStackTests.super.testPush();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testPop() {
|
||||
IIntStackTests.super.testPop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testEnsureCapacity() {
|
||||
IIntArrayTest.super.testEnsureCapacity();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testElements() {
|
||||
IIntArrayTest.super.testElements();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testTrim() {
|
||||
IIntArrayTest.super.testTrim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package speiger.src.collections.ints.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SortingTests
|
||||
{
|
||||
public static final int[] SMALL_TEST = IntStream.range(0, 5000).toArray();
|
||||
public static final int[] LARGE_TEST = IntStream.range(0, 50000).toArray();
|
||||
|
||||
@Test
|
||||
public void testInsertionSort() {
|
||||
int[] array = IntArrays.shuffle(SMALL_TEST.clone());
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.insertionSort(array);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
IntArrays.shuffle(array);
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.insertionSort(array, Integer::compare);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMergeSort() {
|
||||
int[] array = IntArrays.shuffle(SMALL_TEST.clone());
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.mergeSort(array);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
IntArrays.shuffle(array);
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.mergeSort(array, Integer::compare);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemFreeMergeSort() {
|
||||
int[] array = IntArrays.shuffle(SMALL_TEST.clone());
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.memFreeMergeSort(array);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
IntArrays.shuffle(array);
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.memFreeMergeSort(array, Integer::compare);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionSortSort() {
|
||||
int[] array = IntArrays.shuffle(SMALL_TEST.clone());
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.selectionSort(array);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
IntArrays.shuffle(array);
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.selectionSort(array, Integer::compare);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickSortSort() {
|
||||
int[] array = IntArrays.shuffle(SMALL_TEST.clone());
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.quickSort(array);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
IntArrays.shuffle(array);
|
||||
Assert.assertFalse(Arrays.equals(array, SMALL_TEST));
|
||||
IntArrays.quickSort(array, Integer::compare);
|
||||
Assert.assertArrayEquals(SMALL_TEST, array);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParallelMergeSort() {
|
||||
int[] array = IntArrays.shuffle(LARGE_TEST.clone());
|
||||
Assert.assertFalse(Arrays.equals(array, LARGE_TEST));
|
||||
IntArrays.parallelMergeSort(array);
|
||||
Assert.assertArrayEquals(LARGE_TEST, array);
|
||||
IntArrays.shuffle(array);
|
||||
Assert.assertFalse(Arrays.equals(array, LARGE_TEST));
|
||||
IntArrays.parallelMergeSort(array, Integer::compare);
|
||||
Assert.assertArrayEquals(LARGE_TEST, array);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParallelMemFreeMergeSort() {
|
||||
int[] array = IntArrays.shuffle(LARGE_TEST.clone());
|
||||
Assert.assertFalse(Arrays.equals(array, LARGE_TEST));
|
||||
IntArrays.parallelMemFreeMergeSort(array);
|
||||
Assert.assertArrayEquals(LARGE_TEST, array);
|
||||
IntArrays.shuffle(array);
|
||||
Assert.assertFalse(Arrays.equals(array, LARGE_TEST));
|
||||
IntArrays.parallelMemFreeMergeSort(array, Integer::compare);
|
||||
Assert.assertArrayEquals(LARGE_TEST, array);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParallelQuickSort() {
|
||||
int[] array = IntArrays.shuffle(LARGE_TEST.clone());
|
||||
Assert.assertFalse(Arrays.equals(array, LARGE_TEST));
|
||||
IntArrays.parallelQuickSort(array);
|
||||
Assert.assertArrayEquals(LARGE_TEST, array);
|
||||
IntArrays.shuffle(array);
|
||||
Assert.assertFalse(Arrays.equals(array, LARGE_TEST));
|
||||
IntArrays.parallelQuickSort(array, Integer::compare);
|
||||
Assert.assertArrayEquals(LARGE_TEST, array);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package speiger.src.collections.tests;
|
||||
|
||||
public enum CollectionTest
|
||||
{
|
||||
ADD,
|
||||
ADD_ALL,
|
||||
CONTAINS,
|
||||
CONTAINS_ALL,
|
||||
CONTAINS_ANY,
|
||||
REMOVE,
|
||||
REMOVE_IF,
|
||||
REMOVE_ALL,
|
||||
RETAIN_ALL,
|
||||
TO_ARRAY,
|
||||
CLEAR,
|
||||
WRAPPER;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package speiger.src.collections.tests;
|
||||
|
||||
public enum IterableTest
|
||||
{
|
||||
FOR_EACH,
|
||||
ITERATOR_FOR_EACH,
|
||||
ITERATOR_LOOP,
|
||||
ITERATOR_REMOVAL,
|
||||
ITERATOR_SKIP;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package speiger.src.collections.tests;
|
||||
|
||||
public enum ListTest
|
||||
{
|
||||
ADD_INDEX,
|
||||
ADD_LIST,
|
||||
ADD_INDEX_COLLECTION,
|
||||
ADD_INDEX_LIST,
|
||||
ADD_ELEMENTS,
|
||||
INDEX,
|
||||
LAST_INDEX,
|
||||
GET,
|
||||
GET_ELEMENTS,
|
||||
SET,
|
||||
RE_SIZE,
|
||||
SORT,
|
||||
REPLACE,
|
||||
REMOVE,
|
||||
REMOVE_ELEMENTS,
|
||||
EXTRACT_ELEMENTS,
|
||||
LIST_ITERATOR,
|
||||
SUB_LIST;
|
||||
}
|
||||
Reference in New Issue
Block a user