Added Tests for Ordered Maps and more work on completing the

implementation
This commit is contained in:
2026-05-12 13:37:22 +02:00
parent 3d39d5526d
commit 9f46091282
21 changed files with 326 additions and 27 deletions
@@ -20,6 +20,7 @@ import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR;
import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester;
#if !TYPE_OBJECT
import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder;
import speiger.src.testers.objects.generators.TestObjectSetGenerator;
@@ -41,6 +42,7 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU
List<Class<? extends AbstractTester>> testers = super.getTesters();
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester.class);
return testers;
}
@@ -27,6 +27,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester KEY_VALUE_GENERIC_TY
#ignore
@CollectionSize.Require(absent = ZERO)
@SuppressWarnings("unlikely-arg-type")
#endignore
public void testContainsObject_yes() {
assertTrue("contains(present) should return true", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e0())));
@@ -36,6 +37,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester KEY_VALUE_GENERIC_TY
assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(e3()));
}
@SuppressWarnings("unlikely-arg-type")
public void testContainsObject_no() {
assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e3())));
}
@@ -136,6 +136,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester KEY_VALUE_GENERIC
#ignore
@CollectionSize.Require(ONE)
@MapFeature.Require(SUPPORTS_REMOVE)
@SuppressWarnings("unlikely-arg-type")
#endignore
public void testRemove_supportedObjectEntryPresent() {
assertTrue(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e0())));
@@ -154,6 +155,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester KEY_VALUE_GENERIC
#ignore
@CollectionSize.Require(ONE)
@MapFeature.Require(SUPPORTS_REMOVE)
@SuppressWarnings("unlikely-arg-type")
#endignore
public void testRemove_supportedObjectEntryMissing() {
assertFalse(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e3())));
@@ -0,0 +1,122 @@
package speiger.src.testers.PACKAGE.tests.maps;
#ignore
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
import static org.junit.Assert.assertNotEquals;
#endignore
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
import speiger.src.collections.objects.lists.ObjectList;
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
import speiger.src.testers.objects.utils.ObjectHelpers;
@SuppressWarnings("javadoc")
public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
{
private ORDERED_MAP KEY_VALUE_GENERIC_TYPE orderedMap;
private ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE> values;
private KEY_TYPE a;
private VALUE_TYPE aValue;
private VALUE_TYPE cValue;
@Override
public void setUp() throws Exception {
super.setUp();
orderedMap = (ORDERED_MAP KEY_VALUE_GENERIC_TYPE)getMap();
values = ObjectHelpers.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
if (values.size() >= 1) {
a = values.get(0).ENTRY_KEY();
aValue = values.get(0).ENTRY_VALUE();
if (values.size() >= 3) {
cValue = values.get(2).ENTRY_VALUE();
}
}
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testPutFirst() {
assertEquals(aValue, orderedMap.putFirst(a, cValue));
assertNotEquals(cValue, orderedMap.FIRST_ENTRY_VALUE());
assertEquals(orderedMap.getDefaultReturnValue(), orderedMap.putFirst(k4(), v4()));
assertNotEquals(v4(), orderedMap.FIRST_ENTRY_VALUE());
assertEquals(e4(), orderedMap.firstEntry());
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testPutLast() {
assertEquals(aValue, orderedMap.putLast(a, cValue));
assertNotEquals(cValue, orderedMap.LAST_ENTRY_VALUE());
assertEquals(orderedMap.getDefaultReturnValue(), orderedMap.putLast(k4(), v4()));
assertNotEquals(v4(), orderedMap.LAST_ENTRY_VALUE());
assertEquals(e4(), orderedMap.lastEntry());
}
#ignore
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(CollectionSize.ONE)
#endignore
public void testPollFirst() {
assertFalse(orderedMap.isEmpty());
assertEquals(e0(), orderedMap.pollFirstEntry());
assertTrue(orderedMap.isEmpty());
}
#ignore
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(CollectionSize.ONE)
#endignore
public void testPollLast() {
assertFalse(orderedMap.isEmpty());
assertEquals(e0(), orderedMap.pollLastEntry());
assertTrue(orderedMap.isEmpty());
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore
public void testUnsupportedPutFirst() {
try { orderedMap.putFirst(a, aValue); }
catch (UnsupportedOperationException tolerated) {}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore
public void testUnsupportedPutLast() {
try { orderedMap.putLast(a, aValue); }
catch (UnsupportedOperationException tolerated) {}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_REMOVE)
#endignore
public void testUnsupportedPollFirst() {
try { orderedMap.pollFirstEntry(); }
catch (UnsupportedOperationException tolerated) {}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_REMOVE)
#endignore
public void testUnsupportedPollLast() {
try { orderedMap.pollFirstEntry(); }
catch (UnsupportedOperationException tolerated) {}
expectUnchanged();
}
}
@@ -2,6 +2,11 @@ package speiger.src.testers.PACKAGE.tests.queue.iterators;
#if TYPE_OBJECT
import java.util.Objects;
#endif
#if JDK_TYPE
import java.util.OPTIONAL;
#else
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
#endif
import org.junit.Ignore;
@@ -27,17 +32,17 @@ public class FILE_KEY_TYPEQueueFindFirstTester KEY_GENERIC_TYPE extends ABSTRACT
@CollectionSize.Require(absent = CollectionSize.ZERO)
#endignore
public void testQueueFindFirst_FindFirstElements() {
assertEquals("First Element should be found", e0(), queue.findFirst(T -> KEY_EQUALS(T, e0())));
assertEquals("First Element should be found", e0(), queue.findFirst(T -> KEY_EQUALS(T, e0())).SUPPLY_GET());
}
public void testQueueFindFirst_FindNothing() {
assertEquals("No element should be found", EMPTY_KEY_VALUE, queue.findFirst(T -> KEY_EQUALS(T, e4())));
assertEquals("No element should be found", OPTIONAL.empty(), queue.findFirst(T -> KEY_EQUALS(T, e4())));
}
#ignore
@CollectionSize.Require(CollectionSize.SEVERAL)
#endignore
public void testQueueFindFirst_FindLastElement() {
assertEquals("Last Element should be found", e2(), queue.findFirst(T -> KEY_EQUALS(T, e2())));
assertEquals("Last Element should be found", e2(), queue.findFirst(T -> KEY_EQUALS(T, e2())).SUPPLY_GET());
}
}
@@ -3,10 +3,16 @@ package speiger.src.testers.PACKAGE.tests.queue.iterators;
#if TYPE_OBJECT
import java.util.Objects;
#endif
#if JDK_TYPE
import java.util.OPTIONAL;
#else
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
#endif
import org.junit.Ignore;
import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER;
import com.google.common.collect.testing.features.CollectionSize;
@Ignore
@SuppressWarnings("javadoc")
@@ -29,7 +35,7 @@ public class FILE_KEY_TYPEQueueReduceTester KEY_GENERIC_TYPE extends ABSTRACT_QU
}
public void testQueueReduce() {
assertEquals("The sum of the queue should match", getSum(), queue.reduce(this::sum));
assertEquals("The sum of the queue should match", size == CollectionSize.ZERO ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(getSum()), queue.reduce(this::sum));
}
public void testQueueExtraReduce() {