diff options
Diffstat (limited to 'subprojects/store/src/test/java')
-rw-r--r-- | subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java | 38 |
1 files changed, 15 insertions, 23 deletions
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<K, V> { | |||
55 | 55 | ||
56 | public static <K, V> void compareTwoMaps(String title, VersionedMap<K, V> map1, | 56 | public static <K, V> void compareTwoMaps(String title, VersionedMap<K, V> map1, |
57 | VersionedMap<K, V> map2, List<Throwable> errors) { | 57 | VersionedMap<K, V> map2, List<Throwable> errors) { |
58 | map1.checkIntegrity(); | ||
59 | map2.checkIntegrity(); | ||
58 | assertEqualsList(map1.getSize(), map2.getSize(), title + ": Sizes not equal", errors); | 60 | assertEqualsList(map1.getSize(), map2.getSize(), title + ": Sizes not equal", errors); |
59 | |||
60 | Cursor<K, V> cursor1 = map1.getAll(); | ||
61 | Cursor<K, V> cursor2 = map2.getAll(); | ||
62 | while (!cursor1.isTerminated()) { | ||
63 | if (cursor2.isTerminated()) { | ||
64 | fail("cursor 2 terminated before cursor1"); | ||
65 | } | ||
66 | assertEqualsList(cursor1.getKey(), cursor2.getKey(), title + ": Keys not equal", errors); | ||
67 | assertEqualsList(cursor2.getValue(), cursor2.getValue(), title + ": Values not equal", errors); | ||
68 | cursor1.move(); | ||
69 | cursor2.move(); | ||
70 | } | ||
71 | if (!cursor2.isTerminated()) { | ||
72 | fail("cursor 1 terminated before cursor 2"); | ||
73 | } | ||
74 | |||
75 | for (var mode : ContentHashCode.values()) { | 61 | for (var mode : ContentHashCode.values()) { |
76 | assertEqualsList(map1.contentHashCode(mode), map2.contentHashCode(mode), | 62 | assertEqualsList(map1.contentHashCode(mode), map2.contentHashCode(mode), |
77 | title + ": " + mode + " hashCode check", errors); | 63 | title + ": " + mode + " hashCode check", errors); |
@@ -107,29 +93,35 @@ public class MapTestEnvironment<K, V> { | |||
107 | } | 93 | } |
108 | } | 94 | } |
109 | 95 | ||
110 | public VersionedMapImpl<K, V> sut; | 96 | final private VersionedMap<K, V> sut; |
111 | Map<K, V> oracle = new HashMap<K, V>(); | 97 | final private V defaultValue; |
98 | Map<K, V> oracle = new HashMap<>(); | ||
112 | 99 | ||
113 | public MapTestEnvironment(VersionedMapImpl<K, V> sut) { | 100 | public MapTestEnvironment(VersionedMap<K, V> sut) { |
114 | this.sut = sut; | 101 | this.sut = sut; |
102 | this.defaultValue = sut.getDefaultValue(); | ||
115 | } | 103 | } |
116 | 104 | ||
117 | public void put(K key, V value) { | 105 | public void put(K key, V value) { |
118 | V oldSutValue = sut.put(key, value); | 106 | V oldSutValue = sut.put(key, value); |
119 | V oldOracleValue; | 107 | V oldOracleValue; |
120 | if (value != sut.getDefaultValue()) { | 108 | if (value != defaultValue) { |
121 | oldOracleValue = oracle.put(key, value); | 109 | oldOracleValue = oracle.put(key, value); |
122 | } else { | 110 | } else { |
123 | oldOracleValue = oracle.remove(key); | 111 | oldOracleValue = oracle.remove(key); |
124 | } | 112 | } |
125 | if (oldSutValue == sut.getDefaultValue() && oldOracleValue != null) { | 113 | if (oldSutValue == defaultValue && oldOracleValue != null) { |
126 | fail("After put, SUT old nodeId was default, but oracle old value was " + oldOracleValue); | 114 | fail("After put, SUT old nodeId was default, but oracle old value was " + oldOracleValue); |
127 | } | 115 | } |
128 | if (oldSutValue != sut.getDefaultValue()) { | 116 | if (oldSutValue != defaultValue) { |
129 | assertEquals(oldOracleValue, oldSutValue); | 117 | assertEquals(oldOracleValue, oldSutValue); |
130 | } | 118 | } |
131 | } | 119 | } |
132 | 120 | ||
121 | public long commit(){ | ||
122 | return sut.commit(); | ||
123 | } | ||
124 | |||
133 | public void checkEquivalence(String title) { | 125 | public void checkEquivalence(String title) { |
134 | // 0. Checking integrity | 126 | // 0. Checking integrity |
135 | try { | 127 | try { |
@@ -176,7 +168,7 @@ public class MapTestEnvironment<K, V> { | |||
176 | long sutSize = sut.getSize(); | 168 | long sutSize = sut.getSize(); |
177 | if (oracleSize != sutSize || oracleSize != elementsInSutEntrySet) { | 169 | if (oracleSize != sutSize || oracleSize != elementsInSutEntrySet) { |
178 | printComparison(); | 170 | printComparison(); |
179 | fail(title + ": Non-equivalent size() result: SUT.getSize()=" + sutSize + ", SUT.entryset.size=" | 171 | fail(title + ": Non-equivalent size() result: SUT.getSize()=" + sutSize + ", SUT.entrySet.size=" |
180 | + elementsInSutEntrySet + ", Oracle=" + oracleSize + "!"); | 172 | + elementsInSutEntrySet + ", Oracle=" + oracleSize + "!"); |
181 | } | 173 | } |
182 | } | 174 | } |