We are now to 16k tests. Fixed loads of issues.
-Added: Tests for Lists and Sets. -Fixed: SubLists are now stable (they weren't before) -Fixed: All the bugs that the unit tests found so far. -Updated: ReadMe/Changelog
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package speiger.src.collections.objects.list;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.testing.ListTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.TestStringListGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.ListFeature;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.objects.lists.ImmutableObjectList;
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ObjectLinkedList;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ObjectListTests extends TestCase
|
||||
{
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite("Lists");
|
||||
suite.addTest(suite("ArrayList", T -> new ObjectArrayList<>(T)));
|
||||
suite.addTest(suite("LinkedList", T -> new ObjectLinkedList<>(T)));
|
||||
suite.addTest(immutableSuite("ImmutableList", T -> new ImmutableObjectList<>(T)));
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static Test suite(String name, Function<String[], List<String>> factory)
|
||||
{
|
||||
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||
@Override
|
||||
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(ListFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
|
||||
public static Test immutableSuite(String name, Function<String[], List<String>> factory)
|
||||
{
|
||||
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||
@Override
|
||||
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@ import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.testing.AnEnum;
|
||||
import com.google.common.collect.testing.MapTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.TestEnumMapGenerator;
|
||||
import com.google.common.collect.testing.TestStringMapGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
@@ -20,6 +22,9 @@ import speiger.src.collections.objects.maps.impl.customHash.Object2ObjectOpenCus
|
||||
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectLinkedOpenHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectOpenHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.immutable.ImmutableObject2ObjectOpenHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.misc.Enum2ObjectMap;
|
||||
import speiger.src.collections.objects.maps.impl.misc.LinkedEnum2ObjectMap;
|
||||
import speiger.src.collections.objects.maps.impl.misc.Object2ObjectArrayMap;
|
||||
import speiger.src.collections.objects.maps.impl.tree.Object2ObjectAVLTreeMap;
|
||||
import speiger.src.collections.objects.maps.impl.tree.Object2ObjectRBTreeMap;
|
||||
import speiger.src.collections.objects.utils.ObjectStrategy;
|
||||
@@ -34,9 +39,14 @@ public class ObjectMapTests extends TestCase
|
||||
suite.addTest(suite("LinkedHashMap", Object2ObjectLinkedOpenHashMap::new, true));
|
||||
suite.addTest(suite("CustomHashMap", () -> new Object2ObjectOpenCustomHashMap<>(Strategy.INSTANCE), true));
|
||||
suite.addTest(suite("LinkedCustomHashMap", () -> new Object2ObjectLinkedOpenCustomHashMap<>(Strategy.INSTANCE), true));
|
||||
suite.addTest(suite("RBTreeMap", () -> new Object2ObjectRBTreeMap<String, String>(Comparator.naturalOrder()), false));
|
||||
suite.addTest(suite("AVLTreeMap", () -> new Object2ObjectAVLTreeMap<String, String>(Comparator.naturalOrder()), false));
|
||||
suite.addTest(suite("RBTreeMap_NonNull", Object2ObjectRBTreeMap::new, false));
|
||||
suite.addTest(suite("AVLTreeMap_NonNull", Object2ObjectAVLTreeMap::new, false));
|
||||
suite.addTest(suite("RBTreeMap_Null", () -> new Object2ObjectRBTreeMap<>(Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(suite("AVLTreeMap_Null", () -> new Object2ObjectAVLTreeMap<>(Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(immutableSuit("ImmutableMap", ImmutableObject2ObjectOpenHashMap::new));
|
||||
suite.addTest(suite("ArrayMap", Object2ObjectArrayMap::new, true));
|
||||
suite.addTest(enumSuite("EnumMap", () -> new Enum2ObjectMap<>(AnEnum.class)));
|
||||
suite.addTest(enumSuite("LinkedEnumMap", () -> new LinkedEnum2ObjectMap<>(AnEnum.class)));
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -72,6 +82,21 @@ public class ObjectMapTests extends TestCase
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
public static Test enumSuite(String name, Supplier<Map<AnEnum, String>> factory)
|
||||
{
|
||||
MapTestSuiteBuilder<AnEnum, String> builder = MapTestSuiteBuilder.using(new TestEnumMapGenerator() {
|
||||
@Override
|
||||
protected Map<AnEnum, String> create(Map.Entry<AnEnum, String>[] entries) {
|
||||
Map<AnEnum, String> map = factory.get();
|
||||
for(Map.Entry<AnEnum, String> entry : entries) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}).named(name).withFeatures(CollectionSize.ANY, MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
private static class Strategy implements ObjectStrategy<String>
|
||||
{
|
||||
static final Strategy INSTANCE = new Strategy();
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package speiger.src.collections.objects.set;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.testing.SetTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.TestStringSetGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.SetFeature;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.objects.sets.ImmutableObjectOpenHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectAVLTreeSet;
|
||||
import speiger.src.collections.objects.sets.ObjectArraySet;
|
||||
import speiger.src.collections.objects.sets.ObjectLinkedOpenCustomHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOpenCustomHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOpenHashSet;
|
||||
import speiger.src.collections.objects.sets.ObjectRBTreeSet;
|
||||
import speiger.src.collections.objects.utils.ObjectStrategy;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ObjectSetTests extends TestCase
|
||||
{
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite("Sets");
|
||||
suite.addTest(suite("HashSet", ObjectOpenHashSet::new, true));
|
||||
suite.addTest(suite("LinkedHashSet", ObjectLinkedOpenHashSet::new, true));
|
||||
suite.addTest(suite("CustomHashSet", T -> new ObjectOpenCustomHashSet<>(T, Strategy.INSTANCE), true));
|
||||
suite.addTest(suite("LinkedCustomHashSet", T -> new ObjectLinkedOpenCustomHashSet<>(T, Strategy.INSTANCE), true));
|
||||
suite.addTest(immutableSuite("ImmutableHashSet", ImmutableObjectOpenHashSet::new));
|
||||
suite.addTest(suite("ArraySet", ObjectArraySet::new, true));
|
||||
suite.addTest(suite("RBTreeSet_NonNull", ObjectRBTreeSet::new, false));
|
||||
suite.addTest(suite("AVLTreeSet_NonNull", ObjectAVLTreeSet::new, false));
|
||||
suite.addTest(suite("RBTreeSet_Null", T -> new ObjectRBTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(suite("AVLTreeSet_Null", T -> new ObjectAVLTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static Test suite(String name, Function<String[], Set<String>> factory, boolean allowNull)
|
||||
{
|
||||
SetTestSuiteBuilder<String> generator = SetTestSuiteBuilder.using(new TestStringSetGenerator() {
|
||||
@Override
|
||||
protected Set<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE);
|
||||
if(allowNull) generator.withFeatures(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
return generator.createTestSuite();
|
||||
}
|
||||
|
||||
|
||||
public static Test immutableSuite(String name, Function<String[], Set<String>> factory)
|
||||
{
|
||||
return SetTestSuiteBuilder.using(new TestStringSetGenerator() {
|
||||
@Override
|
||||
protected Set<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite();
|
||||
}
|
||||
|
||||
private static class Strategy implements ObjectStrategy<String>
|
||||
{
|
||||
static final Strategy INSTANCE = new Strategy();
|
||||
|
||||
@Override
|
||||
public int hashCode(String o) {
|
||||
return Objects.hashCode(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(String key, String value) {
|
||||
return Objects.equals(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user