diff options
Diffstat (limited to 'model-data/src/test/java/org/eclipse')
-rw-r--r-- | model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java index 8b1760e1..8fd4bece 100644 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java | |||
@@ -15,7 +15,7 @@ import org.eclipse.viatra.solver.data.map.Cursor; | |||
15 | import org.eclipse.viatra.solver.data.map.VersionedMap; | 15 | import org.eclipse.viatra.solver.data.map.VersionedMap; |
16 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; | 16 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; |
17 | 17 | ||
18 | public class MapTestEnvironment<KEY, VALUE> { | 18 | public class MapTestEnvironment<K, V> { |
19 | public static String[] prepareValues(int maxValue) { | 19 | public static String[] prepareValues(int maxValue) { |
20 | String[] values = new String[maxValue]; | 20 | String[] values = new String[maxValue]; |
21 | values[0] = "DEFAULT"; | 21 | values[0] = "DEFAULT"; |
@@ -55,11 +55,11 @@ public class MapTestEnvironment<KEY, VALUE> { | |||
55 | 55 | ||
56 | } | 56 | } |
57 | 57 | ||
58 | public static <KEY, VALUE> void compareTwoMaps(String title, VersionedMapImpl<KEY, VALUE> map1, | 58 | public static <K, V> void compareTwoMaps(String title, VersionedMapImpl<K, V> map1, |
59 | VersionedMapImpl<KEY, VALUE> map2) { | 59 | VersionedMapImpl<K, V> map2) { |
60 | // 1. Comparing cursors. | 60 | // 1. Comparing cursors. |
61 | Cursor<KEY, VALUE> cursor1 = map1.getCursor(); | 61 | Cursor<K, V> cursor1 = map1.getCursor(); |
62 | Cursor<KEY, VALUE> cursor2 = map2.getCursor(); | 62 | Cursor<K, V> cursor2 = map2.getCursor(); |
63 | while (!cursor1.isTerminated()) { | 63 | while (!cursor1.isTerminated()) { |
64 | if (cursor2.isTerminated()) { | 64 | if (cursor2.isTerminated()) { |
65 | fail("cursor 2 terminated before cursor1"); | 65 | fail("cursor 2 terminated before cursor1"); |
@@ -78,14 +78,14 @@ public class MapTestEnvironment<KEY, VALUE> { | |||
78 | assertEquals(map2, map1, title + ": 2.equals(1)"); | 78 | assertEquals(map2, map1, title + ": 2.equals(1)"); |
79 | } | 79 | } |
80 | 80 | ||
81 | public VersionedMapImpl<KEY, VALUE> sut; | 81 | public VersionedMapImpl<K, V> sut; |
82 | Map<KEY, VALUE> oracle = new HashMap<KEY, VALUE>(); | 82 | Map<K, V> oracle = new HashMap<K, V>(); |
83 | 83 | ||
84 | public MapTestEnvironment(VersionedMapImpl<KEY, VALUE> sut) { | 84 | public MapTestEnvironment(VersionedMapImpl<K, V> sut) { |
85 | this.sut = sut; | 85 | this.sut = sut; |
86 | } | 86 | } |
87 | 87 | ||
88 | public void put(KEY key, VALUE value) { | 88 | public void put(K key, V value) { |
89 | sut.put(key, value); | 89 | sut.put(key, value); |
90 | if (value != sut.getDefaultValue()) { | 90 | if (value != sut.getDefaultValue()) { |
91 | oracle.put(key, value); | 91 | oracle.put(key, value); |
@@ -105,9 +105,9 @@ public class MapTestEnvironment<KEY, VALUE> { | |||
105 | // 1. Checking: if Reference contains <key,value> pair, then SUT contains | 105 | // 1. Checking: if Reference contains <key,value> pair, then SUT contains |
106 | // <key,value> pair. | 106 | // <key,value> pair. |
107 | // Tests get functions | 107 | // Tests get functions |
108 | for (Entry<KEY, VALUE> entry : oracle.entrySet()) { | 108 | for (Entry<K, V> entry : oracle.entrySet()) { |
109 | VALUE sutValue = sut.get(entry.getKey()); | 109 | V sutValue = sut.get(entry.getKey()); |
110 | VALUE oracleValue = entry.getValue(); | 110 | V oracleValue = entry.getValue(); |
111 | if (sutValue != oracleValue) { | 111 | if (sutValue != oracleValue) { |
112 | printComparison(); | 112 | printComparison(); |
113 | fail(title + ": Non-equivalent get(" + entry.getKey() + ") results: SUT=" + sutValue + ", Oracle=" | 113 | fail(title + ": Non-equivalent get(" + entry.getKey() + ") results: SUT=" + sutValue + ", Oracle=" |
@@ -119,13 +119,13 @@ public class MapTestEnvironment<KEY, VALUE> { | |||
119 | // <key,value> pair. | 119 | // <key,value> pair. |
120 | // Tests iterators | 120 | // Tests iterators |
121 | int elementsInSutEntrySet = 0; | 121 | int elementsInSutEntrySet = 0; |
122 | Cursor<KEY, VALUE> cursor = sut.getCursor(); | 122 | Cursor<K, V> cursor = sut.getCursor(); |
123 | while (cursor.move()) { | 123 | while (cursor.move()) { |
124 | elementsInSutEntrySet++; | 124 | elementsInSutEntrySet++; |
125 | KEY key = cursor.getKey(); | 125 | K key = cursor.getKey(); |
126 | VALUE sutValue = cursor.getValue(); | 126 | V sutValue = cursor.getValue(); |
127 | // System.out.println(key + " -> " + sutValue); | 127 | // System.out.println(key + " -> " + sutValue); |
128 | VALUE oracleValue = oracle.get(key); | 128 | V oracleValue = oracle.get(key); |
129 | if (sutValue != oracleValue) { | 129 | if (sutValue != oracleValue) { |
130 | printComparison(); | 130 | printComparison(); |
131 | fail(title + ": Non-equivalent entry in iterator: SUT=<" + key + "," + sutValue + ">, Oracle=<" + key | 131 | fail(title + ": Non-equivalent entry in iterator: SUT=<" + key + "," + sutValue + ">, Oracle=<" + key |
@@ -166,23 +166,23 @@ public class MapTestEnvironment<KEY, VALUE> { | |||
166 | printEntrySet(oracle.entrySet().iterator()); | 166 | printEntrySet(oracle.entrySet().iterator()); |
167 | } | 167 | } |
168 | 168 | ||
169 | private void printEntrySet(Iterator<Entry<KEY, VALUE>> iterator) { | 169 | private void printEntrySet(Iterator<Entry<K, V>> iterator) { |
170 | TreeMap<KEY, VALUE> treemap = new TreeMap<>(); | 170 | TreeMap<K, V> treemap = new TreeMap<>(); |
171 | while (iterator.hasNext()) { | 171 | while (iterator.hasNext()) { |
172 | Entry<KEY, VALUE> entry = iterator.next(); | 172 | Entry<K, V> entry = iterator.next(); |
173 | treemap.put(entry.getKey(), entry.getValue()); | 173 | treemap.put(entry.getKey(), entry.getValue()); |
174 | } | 174 | } |
175 | for (Entry<KEY, VALUE> e : treemap.entrySet()) { | 175 | for (Entry<K, V> e : treemap.entrySet()) { |
176 | System.out.println("\t" + e.getKey() + " -> " + e.getValue()); | 176 | System.out.println("\t" + e.getKey() + " -> " + e.getValue()); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ||
180 | private void printEntrySet(Cursor<KEY, VALUE> cursor) { | 180 | private void printEntrySet(Cursor<K, V> cursor) { |
181 | TreeMap<KEY, VALUE> treemap = new TreeMap<>(); | 181 | TreeMap<K, V> treemap = new TreeMap<>(); |
182 | while (cursor.move()) { | 182 | while (cursor.move()) { |
183 | treemap.put(cursor.getKey(), cursor.getValue()); | 183 | treemap.put(cursor.getKey(), cursor.getValue()); |
184 | } | 184 | } |
185 | for (Entry<KEY, VALUE> e : treemap.entrySet()) { | 185 | for (Entry<K, V> e : treemap.entrySet()) { |
186 | System.out.println("\t" + e.getKey() + " -> " + e.getValue()); | 186 | System.out.println("\t" + e.getKey() + " -> " + e.getValue()); |
187 | } | 187 | } |
188 | } | 188 | } |