From e30ca4103f5bbf001723a81fc607552f359cd9f9 Mon Sep 17 00:00:00 2001 From: Speiger Date: Mon, 13 Sep 2021 17:02:24 +0200 Subject: [PATCH] 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. --- .../templates/collections/Collection.template | 2 +- .../templates/lists/ArrayList.template | 3 +- .../LinkedOpenCustomHashMap.template | 18 ++ .../customHash/OpenCustomHashMap.template | 14 +- .../maps/impl/hash/LinkedOpenHashMap.template | 18 ++ .../maps/impl/hash/OpenHashMap.template | 14 +- .../templates/maps/impl/misc/EnumMap.template | 9 + .../sets/LinkedOpenCustomHashSet.template | 16 +- .../templates/sets/LinkedOpenHashSet.template | 16 +- .../templates/sets/OpenCustomHashSet.template | 11 +- .../templates/sets/OpenHashSet.template | 11 +- .../templates/utils/Collections.template | 181 ++++++------------ .../ints/base/BaseIntCollectionTest.java | 15 ++ .../ints/sets/IntHashSetTests.java | 17 ++ .../src/collections/tests/CollectionTest.java | 3 +- 15 files changed, 197 insertions(+), 151 deletions(-) diff --git a/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template b/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template index 190381ba..e72b505a 100644 --- a/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template +++ b/src/builder/resources/speiger/assets/collections/templates/collections/Collection.template @@ -68,7 +68,7 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection, ITE @Primitive public boolean containsAny(Collection c); - #if !TYPE_OBJECT +#if !TYPE_OBJECT /** * A Type-Specific remove function that reduces (un)boxing. * @param o the element that should be removed diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template index 1bf5dff2..2f3247f0 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/ArrayList.template @@ -238,7 +238,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE if(index != size) System.arraycopy(data, index, data, index+add, size - index); size+=add; Iterator iter = c.iterator(); - while(add != 0) data[index++] = OBJ_TO_KEY(iter.next()); + while(add-- != 0) data[index++] = OBJ_TO_KEY(iter.next()); return true; } @@ -935,6 +935,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE return; } data = size == 0 ? EMPTY_KEY_ARRAY : NEW_KEY_ARRAY(size); + this.size = size; } /** diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template index 1d58eecc..cdc0cb7f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/LinkedOpenCustomHashMap.template @@ -423,6 +423,24 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M firstIndex = lastIndex = -1; } + @Override + public void clearAndTrim(int size) { + int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor))); + if(size >= request) { + clear(); + return; + } + nullIndex = request; + mask = request-1; + maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1); + keys = NEW_KEY_ARRAY(request + 1); + values = NEW_VALUE_ARRAY(request + 1); + links = new long[request + 1]; + firstIndex = lastIndex = -1; + this.size = 0; + containsNull = false; + } + protected void moveToFirstIndex(int startPos) { if(size == 1 || firstIndex == startPos) return; if(lastIndex == startPos) { diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template index e73e0dbf..874d4ecc 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template @@ -534,8 +534,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL @Override public void clearAndTrim(int size) { - clear(); - trim(size); + int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor))); + if(size >= request) { + clear(); + return; + } + nullIndex = request; + mask = request-1; + maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1); + keys = NEW_KEY_ARRAY(request + 1); + values = NEW_VALUE_ARRAY(request + 1); + this.size = 0; + containsNull = false; } #if !TYPE_OBJECT diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template index 43eee81b..7c936916 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template @@ -403,6 +403,24 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G firstIndex = lastIndex = -1; } + @Override + public void clearAndTrim(int size) { + int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor))); + if(size >= request) { + clear(); + return; + } + nullIndex = request; + mask = request-1; + maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1); + keys = NEW_KEY_ARRAY(request + 1); + values = NEW_VALUE_ARRAY(request + 1); + links = new long[request + 1]; + firstIndex = lastIndex = -1; + this.size = 0; + containsNull = false; + } + protected void moveToFirstIndex(int startPos) { if(size == 1 || firstIndex == startPos) return; if(lastIndex == startPos) { diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template index 8ba1fcfc..c6b91c60 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template @@ -495,8 +495,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE @Override public void clearAndTrim(int size) { - clear(); - trim(size); + int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor))); + if(size >= request) { + clear(); + return; + } + nullIndex = request; + mask = request-1; + maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1); + keys = NEW_KEY_ARRAY(request + 1); + values = NEW_VALUE_ARRAY(request + 1); + this.size = 0; + containsNull = false; } #if !TYPE_OBJECT diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/EnumMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/EnumMap.template index b1aa0b4d..76d02c85 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/EnumMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/EnumMap.template @@ -1,5 +1,6 @@ package speiger.src.collections.PACKAGE.maps.impl.misc; +import java.util.Arrays; import java.util.Map; import java.util.NoSuchElementException; #if VALUE_OBJECT @@ -193,6 +194,14 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE return valuesC; } + @Override + public void clear() { + if(size == 0) return; + size = 0; + Arrays.fill(present, 0L); + Arrays.fill(values, EMPTY_VALUE); + } + protected void onNodeAdded(int index) { } diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template index 0775717d..eacdaab4 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenCustomHashSet.template @@ -505,17 +505,19 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY @Override public void clearAndTrim(int size) { - if(nullIndex <= size) { + int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor))); + if(size >= request) { clear(); return; } - nullIndex = size; - mask = nullIndex - 1; + nullIndex = request; + mask = request-1; maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1); - keys = NEW_KEY_ARRAY(nullIndex + 1); - links = new long[nullIndex + 1]; - firstIndex = -1; - lastIndex = -1; + keys = NEW_KEY_ARRAY(request + 1); + links = new long[request + 1]; + firstIndex = lastIndex = -1; + this.size = 0; + containsNull = false; } @Override diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template index 78bb3279..a61ef81c 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/LinkedOpenHashSet.template @@ -486,17 +486,19 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE @Override public void clearAndTrim(int size) { - if(nullIndex <= size) { + int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor))); + if(size >= request) { clear(); return; } - nullIndex = size; - mask = nullIndex - 1; + nullIndex = request; + mask = request-1; maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1); - keys = NEW_KEY_ARRAY(nullIndex + 1); - links = new long[nullIndex + 1]; - firstIndex = -1; - lastIndex = -1; + keys = NEW_KEY_ARRAY(request + 1); + links = new long[request + 1]; + firstIndex = lastIndex = -1; + this.size = 0; + containsNull = false; } @Override diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template index 8ec6b8ac..c55e5e01 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenCustomHashSet.template @@ -354,14 +354,17 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T @Override public void clearAndTrim(int size) { - if(nullIndex <= size) { + int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor))); + if(size >= request) { clear(); return; } - nullIndex = size; - mask = nullIndex - 1; + nullIndex = request; + mask = request-1; maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1); - keys = NEW_KEY_ARRAY(nullIndex + 1); + keys = NEW_KEY_ARRAY(request + 1); + this.size = 0; + containsNull = false; } private void ensureCapacity(int newCapacity) { diff --git a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template index 4d246b5e..c6dc99f5 100644 --- a/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template +++ b/src/builder/resources/speiger/assets/collections/templates/sets/OpenHashSet.template @@ -312,14 +312,17 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp @Override public void clearAndTrim(int size) { - if(nullIndex <= size) { + int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor))); + if(size >= request) { clear(); return; } - nullIndex = size; - mask = nullIndex - 1; + nullIndex = request; + mask = request-1; maxFill = Math.min((int)Math.ceil(nullIndex * loadFactor), nullIndex - 1); - keys = NEW_KEY_ARRAY(nullIndex + 1); + keys = NEW_KEY_ARRAY(request + 1); + this.size = 0; + containsNull = false; } @Override diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template b/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template index ce53ed1a..b69c6b31 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template @@ -5,12 +5,14 @@ import java.util.function.Predicate; #if PRIMITIVES import java.util.function.JAVA_PREDICATE; #endif +import java.util.function.Consumer; import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION; import speiger.src.collections.PACKAGE.collections.COLLECTION; import speiger.src.collections.PACKAGE.collections.ITERATOR; import speiger.src.collections.objects.utils.ObjectArrays; #if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.utils.ARRAYS; #endif @@ -151,23 +153,32 @@ public class COLLECTIONS #endif @Override public void clear() { synchronized(mutex) { c.clear(); } } - @Override public Object[] toArray() { synchronized(mutex) { return c.toArray(); } } - #if !TYPE_OBJECT @Override public T[] toArray(T[] a) { synchronized(mutex) { return c.toArray(a); } } - @Override public KEY_TYPE[] TO_ARRAY() { synchronized(mutex) { return c.TO_ARRAY(); } } - @Override public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { synchronized(mutex) { return c.TO_ARRAY(a); } } + @Override + public void forEach(CONSUMER action) { synchronized(mutex) { c.forEach(action); } } + @Override + @Deprecated + public void forEach(Consumer action) { synchronized(mutex) { c.forEach(action); } } #else @Override public E[] toArray(E[] a) { synchronized(mutex) { return c.toArray(a); } } + @Override + public void forEach(Consumer action) { synchronized(mutex) { c.forEach(action); } } #endif + @Override + public int hashCode() { synchronized(mutex) { return c.hashCode(); } } + @Override + public boolean equals(Object obj) { synchronized(mutex) { return c.equals(obj); } } + @Override + public String toString() { synchronized(mutex) { return c.toString(); } } } /** @@ -187,57 +198,29 @@ public class COLLECTIONS public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } @Override public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } - #if !TYPE_OBJECT @Override - public boolean contains(KEY_TYPE o) { - return c.contains(o); - } - + public boolean contains(KEY_TYPE o) { return c.contains(o); } #else @Override - public boolean contains(Object o) { - return c.contains(o); - } - + public boolean contains(Object o) { return c.contains(o); } #endif @Override - public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { - return this.c.containsAll(c); - } - + public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return this.c.containsAll(c); } @Override - public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { - return this.c.containsAny(c); - } - + public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { return this.c.containsAny(c); } @Override @Primitive - public boolean containsAny(Collection c) { - return this.c.containsAny(c); - } - + public boolean containsAny(Collection c) { return this.c.containsAny(c); } @Override @Primitive - public boolean containsAll(Collection c) { - return this.c.containsAll(c); - } - + public boolean containsAll(Collection c) { return this.c.containsAll(c); } @Override - public int size() { - return c.size(); - } - + public int size() { return c.size(); } @Override - public boolean isEmpty() { - return c.isEmpty(); - } - + public boolean isEmpty() { return c.isEmpty(); } @Override - public ITERATOR KEY_GENERIC_TYPE iterator() { - return ITERATORS.unmodifiable(c.iterator()); - } - + public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(c.iterator()); } @Override @Deprecated public boolean remove(Object o) { throw new UnsupportedOperationException(); } @@ -264,35 +247,32 @@ public class COLLECTIONS #endif @Override public void clear() { throw new UnsupportedOperationException(); } - @Override - public Object[] toArray() { - return c.toArray(); - } - + public Object[] toArray() { return c.toArray(); } #if !TYPE_OBJECT @Override - public T[] toArray(T[] a) { - return c.toArray(a); - } - + public T[] toArray(T[] a) { return c.toArray(a); } @Override - public KEY_TYPE[] TO_ARRAY() { - return c.TO_ARRAY(); - } - + public KEY_TYPE[] TO_ARRAY() { return c.TO_ARRAY(); } @Override - public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { - return c.TO_ARRAY(a); - } - + public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { return c.TO_ARRAY(a); } + @Override + public void forEach(CONSUMER action) { c.forEach(action); } + @Override + @Deprecated + public void forEach(Consumer action) { c.forEach(action); } #else @Override - public E[] toArray(E[] a) { - return c.toArray(a); - } - + public E[] toArray(E[] a) { return c.toArray(a); } + @Override + public void forEach(Consumer action) { c.forEach(action); } #endif + @Override + public int hashCode() { return c.hashCode(); } + @Override + public boolean equals(Object obj) { return c.equals(obj); } + @Override + public String toString() { return c.toString(); } } /** @@ -308,43 +288,23 @@ public class COLLECTIONS #if !TYPE_OBJECT @Override - public boolean contains(KEY_TYPE o) { - return false; - } - + public boolean contains(KEY_TYPE o) { return false; } @Override - public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { - return false; - } - + public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return false; } @Override - public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { - return false; - } - + public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { return false; } #else @Override - public boolean contains(Object o) { - return false; - } - + public boolean contains(Object o) { return false; } #endif @Override @Primitive - public boolean containsAny(Collection c) { - return false; - } - + public boolean containsAny(Collection c) { return false; } @Override @Primitive - public boolean containsAll(Collection c) { - return false; - } - + public boolean containsAll(Collection c) { return false; } @Override - public int hashCode() { - return 0; - } + public int hashCode() { return 0; } @Override public boolean equals(Object o) { @@ -377,47 +337,24 @@ public class COLLECTIONS @Override public boolean remIf(JAVA_PREDICATE filter){ throw new UnsupportedOperationException(); } #endif - @Override - public Object[] toArray() { - return ObjectArrays.EMPTY_ARRAY; - } - + public Object[] toArray() { return ObjectArrays.EMPTY_ARRAY; } #if !TYPE_OBJECT @Override - public T[] toArray(T[] a) { - return a; - } - + public T[] toArray(T[] a) { return a; } @Override - public KEY_TYPE[] TO_ARRAY() { - return ARRAYS.EMPTY_ARRAY; - } - + public KEY_TYPE[] TO_ARRAY() { return ARRAYS.EMPTY_ARRAY; } @Override - public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { - return a; - } - -#else + public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { return a; } +#else @Override - public E[] toArray(E[] a) { - return a; - } - + public E[] toArray(E[] a) { return a; } #endif @Override - public ITERATOR KEY_GENERIC_TYPE iterator() { - return ITERATORS.empty(); - } - + public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.empty(); } @Override - public void clear() { - } - + public void clear() {} @Override - public int size() { - return 0; - } + public int size() { return 0; } } -} +} \ No newline at end of file diff --git a/src/test/java/speiger/src/collections/ints/base/BaseIntCollectionTest.java b/src/test/java/speiger/src/collections/ints/base/BaseIntCollectionTest.java index 7dcedfb5..a64232df 100644 --- a/src/test/java/speiger/src/collections/ints/base/BaseIntCollectionTest.java +++ b/src/test/java/speiger/src/collections/ints/base/BaseIntCollectionTest.java @@ -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 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()); + } } \ No newline at end of file diff --git a/src/test/java/speiger/src/collections/ints/sets/IntHashSetTests.java b/src/test/java/speiger/src/collections/ints/sets/IntHashSetTests.java index 940af4dc..432e635f 100644 --- a/src/test/java/speiger/src/collections/ints/sets/IntHashSetTests.java +++ b/src/test/java/speiger/src/collections/ints/sets/IntHashSetTests.java @@ -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 getValidCollectionTests() + { + EnumSet 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 getValidCollectionTests() + { + EnumSet tests = super.getValidCollectionTests(); + tests.remove(CollectionTest.TO_STRING); + return tests; + } } public static class IntLinkedOpenCustomHashSetTests extends BaseIntOpenHashSetTests diff --git a/src/test/java/speiger/src/collections/tests/CollectionTest.java b/src/test/java/speiger/src/collections/tests/CollectionTest.java index 93065090..aa128f25 100644 --- a/src/test/java/speiger/src/collections/tests/CollectionTest.java +++ b/src/test/java/speiger/src/collections/tests/CollectionTest.java @@ -14,5 +14,6 @@ public enum CollectionTest RETAIN_ALL, TO_ARRAY, CLEAR, - WRAPPER; + WRAPPER, + TO_STRING; }