Finished the Basic Unit test frame work to ensure stablity.
-Added: 150k Unit tests. -Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
package speiger.src.collections.ints.maps;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
|
||||
import speiger.src.collections.ints.maps.impl.misc.Int2IntArrayMap;
|
||||
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
|
||||
import speiger.src.collections.tests.SortedMapTests;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Int2IntArrayMapTest extends BaseInt2IntSortedMapTest
|
||||
{
|
||||
@Override
|
||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.SUB_MAP, SortedMapTests.HEAD_MAP, SortedMapTests.TAIL_MAP)); }
|
||||
|
||||
@Override
|
||||
public Int2IntSortedMap createMap(int[] keys, int[] values)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package speiger.src.collections.ints.sets;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import speiger.src.collections.ints.base.BaseIntSortedSetTest;
|
||||
import speiger.src.collections.tests.SortedSetTest;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class IntArraySetTests extends BaseIntSortedSetTest
|
||||
{
|
||||
@Override
|
||||
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.complementOf(EnumSet.of(SortedSetTest.SUB_SET, SortedSetTest.HEAD_SET, SortedSetTest.TAIL_SET)); }
|
||||
@Override
|
||||
protected IntSortedSet create(int[] data) { return new IntArraySet(data.clone()); }
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@ package speiger.src.collections.objects.map;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
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.NavigableMapTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.TestEnumMapGenerator;
|
||||
import com.google.common.collect.testing.TestStringMapGenerator;
|
||||
import com.google.common.collect.testing.TestStringSortedMapGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.MapFeature;
|
||||
@@ -39,10 +42,10 @@ 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_NonNull", Object2ObjectRBTreeMap::new, false));
|
||||
suite.addTest(suite("AVLTreeMap_NonNull", Object2ObjectAVLTreeMap::new, false));
|
||||
suite.addTest(suite("RBTreeMap_Null", () -> new Object2ObjectRBTreeMap<String, String>(Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(suite("AVLTreeMap_Null", () -> new Object2ObjectAVLTreeMap<String, String>(Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(navigableSuite("RBTreeMap_NonNull", Object2ObjectRBTreeMap::new, false));
|
||||
suite.addTest(navigableSuite("AVLTreeMap_NonNull", Object2ObjectAVLTreeMap::new, false));
|
||||
suite.addTest(navigableSuite("RBTreeMap_Null", () -> new Object2ObjectRBTreeMap<>(new NullFriendlyComparator()), true));
|
||||
suite.addTest(navigableSuite("AVLTreeMap_Null", () -> new Object2ObjectAVLTreeMap<>(new NullFriendlyComparator()), true));
|
||||
suite.addTest(immutableSuit("ImmutableMap", ImmutableObject2ObjectOpenHashMap::new));
|
||||
suite.addTest(suite("ArrayMap", Object2ObjectArrayMap::new, true));
|
||||
suite.addTest(enumSuite("EnumMap", () -> new Enum2ObjectMap<>(AnEnum.class)));
|
||||
@@ -66,6 +69,22 @@ public class ObjectMapTests extends TestCase
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
public static Test navigableSuite(String name, Supplier<NavigableMap<String, String>> factory, boolean allowNull)
|
||||
{
|
||||
MapTestSuiteBuilder<String, String> builder = NavigableMapTestSuiteBuilder.using(new TestStringSortedMapGenerator() {
|
||||
@Override
|
||||
protected NavigableMap<String, String> create(Map.Entry<String, String>[] entries) {
|
||||
NavigableMap<String, String> map = factory.get();
|
||||
for(Map.Entry<String, 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);
|
||||
if(allowNull) builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_ANY_NULL_QUERIES);
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
public static Test immutableSuit(String name, BiFunction<String[], String[], Map<String, String>> factory) {
|
||||
MapTestSuiteBuilder<String, String> builder = MapTestSuiteBuilder.using(new TestStringMapGenerator() {
|
||||
@Override
|
||||
@@ -97,6 +116,14 @@ public class ObjectMapTests extends TestCase
|
||||
return builder.createTestSuite();
|
||||
}
|
||||
|
||||
private static final class NullFriendlyComparator implements Comparator<String>
|
||||
{
|
||||
@Override
|
||||
public int compare(String left, String right) {
|
||||
return String.valueOf(left).compareTo(String.valueOf(right));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Strategy implements ObjectStrategy<String>
|
||||
{
|
||||
static final Strategy INSTANCE = new Strategy();
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package speiger.src.collections.objects.set;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.testing.NavigableSetTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.SetTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.TestStringSetGenerator;
|
||||
import com.google.common.collect.testing.TestStringSortedSetGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.SetFeature;
|
||||
@@ -36,15 +39,14 @@ public class ObjectSetTests extends TestCase
|
||||
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));
|
||||
suite.addTest(navigableSuite("RBTreeSet_NonNull", ObjectRBTreeSet::new, false));
|
||||
suite.addTest(navigableSuite("AVLTreeSet_NonNull", ObjectAVLTreeSet::new, false));
|
||||
suite.addTest(navigableSuite("RBTreeSet_Null", T -> new ObjectRBTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||
suite.addTest(navigableSuite("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)
|
||||
{
|
||||
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); }
|
||||
@@ -53,17 +55,23 @@ public class ObjectSetTests extends TestCase
|
||||
return generator.createTestSuite();
|
||||
}
|
||||
|
||||
public static Test navigableSuite(String name, Function<String[], NavigableSet<String>> factory, boolean allowNull) {
|
||||
SetTestSuiteBuilder<String> generator = NavigableSetTestSuiteBuilder.using(new TestStringSortedSetGenerator() {
|
||||
@Override
|
||||
protected NavigableSet<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)
|
||||
{
|
||||
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>
|
||||
{
|
||||
private static class Strategy implements ObjectStrategy<String> {
|
||||
static final Strategy INSTANCE = new Strategy();
|
||||
|
||||
@Override
|
||||
@@ -75,6 +83,5 @@ public class ObjectSetTests extends TestCase
|
||||
public boolean equals(String key, String value) {
|
||||
return Objects.equals(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user