Fixed recent found bugs

-Fixed: addAll with non Specific Collections was crashing lists.
-Fixed/Refactor: Clear and trim implementation was all over the place
-Fixed: Wrappers toString/hashCode/equals function wasn't implemented
-Added: Tests for addAll bug
-Refactor: Did small code style cleanups as I was fixing bugs.
This commit is contained in:
2021-09-13 17:02:24 +02:00
parent ec817fb9c2
commit e30ca4103f
15 changed files with 197 additions and 151 deletions
@@ -2,6 +2,7 @@ package speiger.src.collections.ints.base;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.IntStream;
import org.junit.Assert;
@@ -12,6 +13,7 @@ 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.objects.lists.ObjectArrayList;
import speiger.src.collections.tests.CollectionTest;
@SuppressWarnings("javadoc")
@@ -47,6 +49,9 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
Assert.assertEquals(TEST_ARRAY.length, collection.size());
collection.addAll(create(BULK_ADD_ARRAY));
Assert.assertEquals(TEST_ARRAY.length + BULK_ADD_ARRAY.length, collection.size());
// Testing if adding via non Type Specific work like they should
List<Integer> wrapper = new ObjectArrayList<>(create(ADD_ARRAY));
Assert.assertNotNull(create(ADD_ARRAY).addAll(wrapper));
}
@Test
@@ -163,4 +168,14 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
collection = IntCollections.unmodifiable(collection);
Assert.assertTrue(collection instanceof UnmodifiableCollection);
}
@Test
public void testToString() {
if(!getValidCollectionTests().contains(CollectionTest.TO_STRING)) return;
String base = Arrays.toString(BULK_ADD_ARRAY);
IntCollection collection = create(BULK_ADD_ARRAY);
Assert.assertEquals(base, collection.toString());
Assert.assertEquals(base, IntCollections.synchronize(collection).toString());
Assert.assertEquals(base, IntCollections.unmodifiable(collection).toString());
}
}
@@ -6,6 +6,7 @@ import speiger.src.collections.ints.base.BaseIntCollectionTest;
import speiger.src.collections.ints.base.BaseIntSortedSetTest;
import speiger.src.collections.ints.collections.IntCollection;
import speiger.src.collections.ints.utils.IntStrategy;
import speiger.src.collections.tests.CollectionTest;
import speiger.src.collections.tests.SortedSetTest;
@SuppressWarnings("javadoc")
@@ -21,6 +22,14 @@ public class IntHashSetTests
{
@Override
protected IntCollection create(int[] data) { return new IntOpenHashSet(data); }
@Override
protected EnumSet<CollectionTest> getValidCollectionTests()
{
EnumSet<CollectionTest> tests = super.getValidCollectionTests();
tests.remove(CollectionTest.TO_STRING);
return tests;
}
}
public static class IntLinkedOpenHashSetTests extends BaseIntOpenHashSetTests
@@ -33,6 +42,14 @@ public class IntHashSetTests
{
@Override
protected IntCollection create(int[] data) { return new IntOpenCustomHashSet(data, new DefaultStrategy()); }
@Override
protected EnumSet<CollectionTest> getValidCollectionTests()
{
EnumSet<CollectionTest> tests = super.getValidCollectionTests();
tests.remove(CollectionTest.TO_STRING);
return tests;
}
}
public static class IntLinkedOpenCustomHashSetTests extends BaseIntOpenHashSetTests
@@ -14,5 +14,6 @@ public enum CollectionTest
RETAIN_ALL,
TO_ARRAY,
CLEAR,
WRAPPER;
WRAPPER,
TO_STRING;
}