From 6598f296d79382a7eaf6ec42819d0123b0acc0d1 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Tue, 14 Feb 2023 00:43:00 +0100 Subject: Test environment cannot rely upon the order of elements in a map since VersionedMapDelta appeared. --- .../store/map/tests/utils/MapTestEnvironment.java | 38 +++++++++------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'subprojects/store/src/test/java') diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java index 30f38201..69ae811e 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java @@ -55,23 +55,9 @@ public class MapTestEnvironment { public static void compareTwoMaps(String title, VersionedMap map1, VersionedMap map2, List errors) { + map1.checkIntegrity(); + map2.checkIntegrity(); assertEqualsList(map1.getSize(), map2.getSize(), title + ": Sizes not equal", errors); - - Cursor cursor1 = map1.getAll(); - Cursor cursor2 = map2.getAll(); - while (!cursor1.isTerminated()) { - if (cursor2.isTerminated()) { - fail("cursor 2 terminated before cursor1"); - } - assertEqualsList(cursor1.getKey(), cursor2.getKey(), title + ": Keys not equal", errors); - assertEqualsList(cursor2.getValue(), cursor2.getValue(), title + ": Values not equal", errors); - cursor1.move(); - cursor2.move(); - } - if (!cursor2.isTerminated()) { - fail("cursor 1 terminated before cursor 2"); - } - for (var mode : ContentHashCode.values()) { assertEqualsList(map1.contentHashCode(mode), map2.contentHashCode(mode), title + ": " + mode + " hashCode check", errors); @@ -107,29 +93,35 @@ public class MapTestEnvironment { } } - public VersionedMapImpl sut; - Map oracle = new HashMap(); + final private VersionedMap sut; + final private V defaultValue; + Map oracle = new HashMap<>(); - public MapTestEnvironment(VersionedMapImpl sut) { + public MapTestEnvironment(VersionedMap sut) { this.sut = sut; + this.defaultValue = sut.getDefaultValue(); } public void put(K key, V value) { V oldSutValue = sut.put(key, value); V oldOracleValue; - if (value != sut.getDefaultValue()) { + if (value != defaultValue) { oldOracleValue = oracle.put(key, value); } else { oldOracleValue = oracle.remove(key); } - if (oldSutValue == sut.getDefaultValue() && oldOracleValue != null) { + if (oldSutValue == defaultValue && oldOracleValue != null) { fail("After put, SUT old nodeId was default, but oracle old value was " + oldOracleValue); } - if (oldSutValue != sut.getDefaultValue()) { + if (oldSutValue != defaultValue) { assertEquals(oldOracleValue, oldSutValue); } } + public long commit(){ + return sut.commit(); + } + public void checkEquivalence(String title) { // 0. Checking integrity try { @@ -176,7 +168,7 @@ public class MapTestEnvironment { long sutSize = sut.getSize(); if (oracleSize != sutSize || oracleSize != elementsInSutEntrySet) { printComparison(); - fail(title + ": Non-equivalent size() result: SUT.getSize()=" + sutSize + ", SUT.entryset.size=" + fail(title + ": Non-equivalent size() result: SUT.getSize()=" + sutSize + ", SUT.entrySet.size=" + elementsInSutEntrySet + ", Oracle=" + oracleSize + "!"); } } -- cgit v1.2.3-70-g09d2