[1285] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
| 15 | package de.ugoe.cs.autoquest.tasktrees.temporalrelation; |
---|
| 16 | |
---|
| 17 | import static org.junit.Assert.*; |
---|
| 18 | |
---|
| 19 | import java.util.ArrayList; |
---|
| 20 | import java.util.HashMap; |
---|
| 21 | import java.util.HashSet; |
---|
| 22 | import java.util.Iterator; |
---|
| 23 | import java.util.List; |
---|
| 24 | import java.util.Map; |
---|
| 25 | import java.util.Set; |
---|
| 26 | |
---|
| 27 | import org.junit.Before; |
---|
| 28 | import org.junit.Test; |
---|
| 29 | |
---|
[1294] | 30 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
| 31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
| 32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
[1285] | 33 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 34 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; |
---|
| 35 | import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskFactory; |
---|
| 36 | import de.ugoe.cs.autoquest.test.DummyGUIElement; |
---|
| 37 | import de.ugoe.cs.autoquest.test.DummyInteraction; |
---|
| 38 | import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * <p> |
---|
| 42 | * The class <code>SymbolMapTest</code> contains tests for the class |
---|
| 43 | * <code>{@link SymbolMap}</code>. |
---|
| 44 | * </p> |
---|
| 45 | * |
---|
| 46 | * @author Patrick Harms |
---|
| 47 | */ |
---|
| 48 | public class TaskSymbolIdentityMapTest { |
---|
| 49 | |
---|
| 50 | /** */ |
---|
| 51 | private ITaskFactory taskFactory = new TaskFactory(); |
---|
| 52 | |
---|
| 53 | /** */ |
---|
| 54 | Map<String, ITask> tasks = new HashMap<String, ITask>(); |
---|
| 55 | |
---|
| 56 | @Before |
---|
| 57 | public void setUp() { |
---|
| 58 | tasks = new HashMap<String, ITask>(); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | @Test |
---|
| 62 | public void testSymbolMap_1() { |
---|
[1846] | 63 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 64 | |
---|
| 65 | assertNotNull(symbolMap); |
---|
| 66 | assertEquals(0, symbolMap.size()); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | @Test |
---|
| 70 | public void testSymbolMap_2() { |
---|
| 71 | TaskSymbolIdentityMap<String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
| 72 | |
---|
[1846] | 73 | ITask task = createTask("symbol"); |
---|
| 74 | symbolMap1.addSymbol(task, "value"); |
---|
[1285] | 75 | |
---|
[1846] | 76 | SymbolMap<ITask, String> symbolMap2 = new TaskSymbolIdentityMap<String>(symbolMap1); |
---|
[1285] | 77 | |
---|
| 78 | assertNotNull(symbolMap2); |
---|
[1846] | 79 | assertSymbolMapEntries(symbolMap2, new ITask[] { task }, |
---|
[1285] | 80 | new String[] { "value" }); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
| 84 | public void testSymbolMap_3() throws Exception { |
---|
| 85 | new TaskSymbolBucketedMap<String>((TaskSymbolBucketedMap<String>) null); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | @Test |
---|
| 89 | public void testAddSymbol_1() { |
---|
[1846] | 90 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 91 | |
---|
[1846] | 92 | ITask task = createTask("symbol"); |
---|
| 93 | symbolMap.addSymbol(task, "value1"); |
---|
[1285] | 94 | |
---|
| 95 | assertNotNull(symbolMap); |
---|
[1846] | 96 | assertSymbolMapEntries(symbolMap, new ITask[] { task }, |
---|
[1285] | 97 | new String[] { "value1" }); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | @Test |
---|
| 101 | public void testAddSymbol_2() { |
---|
[1846] | 102 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 103 | |
---|
| 104 | int entryCount = 2000; |
---|
| 105 | |
---|
[1846] | 106 | ITask[] symbols = new ITask[entryCount]; |
---|
[1285] | 107 | String[] values = new String[entryCount]; |
---|
| 108 | |
---|
| 109 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 110 | symbols[i] = createTask("symbol" + i); |
---|
[1285] | 111 | symbolMap.addSymbol(symbols[i], "value" + i); |
---|
| 112 | values[i] = "value" + i; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | assertNotNull(symbolMap); |
---|
| 116 | assertSymbolMapEntries(symbolMap, symbols, values); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | @Test |
---|
| 120 | public void testAddSymbol_3() { |
---|
[1846] | 121 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 122 | |
---|
| 123 | int entryCount = 2000; |
---|
| 124 | |
---|
[1846] | 125 | ITask[] symbols = new ITask[entryCount]; |
---|
[1285] | 126 | String[] values = new String[entryCount]; |
---|
| 127 | |
---|
| 128 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 129 | symbols[i] = createTask("symbol" + i); |
---|
[1285] | 130 | if (i % 7 == 0) { |
---|
| 131 | values[i] = "value" + i; |
---|
| 132 | } |
---|
| 133 | else { |
---|
| 134 | values[i] = null; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | symbolMap.addSymbol(symbols[i], values[i]); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | assertNotNull(symbolMap); |
---|
| 141 | assertSymbolMapEntries(symbolMap, symbols, values); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
| 145 | public void testAddSymbol_4() { |
---|
[1846] | 146 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 147 | |
---|
| 148 | symbolMap.addSymbol(null, null); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | @Test |
---|
| 152 | public void testSize_1() { |
---|
[1846] | 153 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 154 | |
---|
| 155 | assertEquals(0, symbolMap.size()); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | @Test |
---|
| 159 | public void testSize_2() { |
---|
[1846] | 160 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 161 | |
---|
[1846] | 162 | symbolMap.addSymbol(createTask("symbol1"), "value1"); |
---|
[1285] | 163 | |
---|
| 164 | assertEquals(1, symbolMap.size()); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | @Test |
---|
| 168 | public void testSize_3() { |
---|
[1846] | 169 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 170 | |
---|
| 171 | int entryCount = 2000; |
---|
| 172 | |
---|
| 173 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 174 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 175 | } |
---|
| 176 | |
---|
| 177 | assertEquals(entryCount, symbolMap.size()); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | @Test |
---|
| 181 | public void testSize_4() { |
---|
[1846] | 182 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 183 | |
---|
| 184 | int entryCount = 2000; |
---|
| 185 | |
---|
| 186 | for (int i = 0; i < entryCount; i++) { |
---|
| 187 | if (i % 7 == 0) { |
---|
[1846] | 188 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 189 | } |
---|
| 190 | else { |
---|
[1846] | 191 | symbolMap.addSymbol(createTask("symbol" + i), null); |
---|
[1285] | 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | assertEquals(entryCount, symbolMap.size()); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | @Test |
---|
| 199 | public void testSize_5() { |
---|
[1846] | 200 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 201 | |
---|
| 202 | int entryCount = 2000; |
---|
| 203 | |
---|
| 204 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 205 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 206 | } |
---|
| 207 | |
---|
| 208 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 209 | symbolMap.removeSymbol(createTask("symbol" + i)); |
---|
[1285] | 210 | } |
---|
| 211 | |
---|
| 212 | assertEquals(2 * 150, symbolMap.size()); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | @Test |
---|
| 216 | public void testIsEmpty_1() { |
---|
[1846] | 217 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 218 | |
---|
| 219 | assertTrue(symbolMap.isEmpty()); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | @Test |
---|
| 223 | public void testIsEmpty_2() { |
---|
[1846] | 224 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 225 | |
---|
[1846] | 226 | symbolMap.addSymbol(createTask("symbol1"), "value1"); |
---|
[1285] | 227 | |
---|
| 228 | assertFalse(symbolMap.isEmpty()); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | @Test |
---|
| 232 | public void testIsEmpty_3() { |
---|
[1846] | 233 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 234 | |
---|
| 235 | int entryCount = 2000; |
---|
| 236 | |
---|
| 237 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 238 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 239 | } |
---|
| 240 | |
---|
| 241 | assertFalse(symbolMap.isEmpty()); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | @Test |
---|
| 245 | public void testIsEmpty_4() { |
---|
[1846] | 246 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 247 | |
---|
| 248 | int entryCount = 2000; |
---|
| 249 | |
---|
| 250 | for (int i = 0; i < entryCount; i++) { |
---|
| 251 | if (i % 7 == 0) { |
---|
[1846] | 252 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 253 | } |
---|
| 254 | else { |
---|
[1846] | 255 | symbolMap.addSymbol(createTask("symbol" + i), null); |
---|
[1285] | 256 | } |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | assertFalse(symbolMap.isEmpty()); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | @Test |
---|
| 263 | public void testIsEmpty_5() { |
---|
[1846] | 264 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 265 | |
---|
| 266 | int entryCount = 2000; |
---|
| 267 | |
---|
| 268 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 269 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 270 | } |
---|
| 271 | |
---|
| 272 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 273 | symbolMap.removeSymbol(createTask("symbol" + i)); |
---|
[1285] | 274 | } |
---|
| 275 | |
---|
| 276 | assertFalse(symbolMap.isEmpty()); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | @Test |
---|
| 280 | public void testContainsSymbol_1() { |
---|
[1846] | 281 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 282 | |
---|
[1846] | 283 | assertFalse(symbolMap.containsSymbol(createTask("symbol"))); |
---|
[1285] | 284 | } |
---|
| 285 | |
---|
| 286 | @Test |
---|
| 287 | public void testContainsSymbol_2() { |
---|
[1846] | 288 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 289 | |
---|
[1846] | 290 | symbolMap.addSymbol(createTask("symbol1"), "value1"); |
---|
[1285] | 291 | |
---|
[1846] | 292 | assertTrue(symbolMap.containsSymbol(createTask("symbol1"))); |
---|
[1285] | 293 | } |
---|
| 294 | |
---|
| 295 | @Test |
---|
| 296 | public void testContainsSymbol_3() { |
---|
[1846] | 297 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 298 | |
---|
| 299 | int entryCount = 2000; |
---|
| 300 | |
---|
| 301 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 302 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 303 | } |
---|
| 304 | |
---|
| 305 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 306 | assertTrue(symbolMap.containsSymbol(createTask("symbol" + i))); |
---|
[1285] | 307 | } |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | @Test |
---|
| 311 | public void testContainsSymbol_4() { |
---|
[1846] | 312 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 313 | |
---|
| 314 | int entryCount = 2000; |
---|
| 315 | |
---|
| 316 | for (int i = 0; i < entryCount; i++) { |
---|
| 317 | if (i % 7 == 0) { |
---|
[1846] | 318 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 319 | } |
---|
| 320 | else { |
---|
[1846] | 321 | symbolMap.addSymbol(createTask("symbol" + i), null); |
---|
[1285] | 322 | } |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 326 | assertTrue(symbolMap.containsSymbol(createTask("symbol" + i))); |
---|
[1285] | 327 | } |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | @Test |
---|
| 331 | public void testContainsSymbol_5() { |
---|
[1846] | 332 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 333 | |
---|
| 334 | int entryCount = 2000; |
---|
| 335 | |
---|
| 336 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 337 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 338 | } |
---|
| 339 | |
---|
| 340 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 341 | symbolMap.removeSymbol(createTask("symbol" + i)); |
---|
[1285] | 342 | } |
---|
| 343 | |
---|
| 344 | for (int i = 0; i < 150; i++) { |
---|
[1846] | 345 | assertTrue(symbolMap.containsSymbol(createTask("symbol" + i))); |
---|
[1285] | 346 | } |
---|
| 347 | |
---|
| 348 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 349 | assertFalse(symbolMap.containsSymbol(createTask("symbol" + i))); |
---|
[1285] | 350 | } |
---|
| 351 | |
---|
| 352 | for (int i = (entryCount - 150); i < entryCount; i++) { |
---|
[1846] | 353 | assertTrue(symbolMap.containsSymbol(createTask("symbol" + i))); |
---|
[1285] | 354 | } |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
| 358 | public void testContainsSymbol_6() { |
---|
[1846] | 359 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 360 | |
---|
| 361 | symbolMap.containsSymbol(null); |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | @Test |
---|
| 365 | public void testGetValue_1() { |
---|
[1846] | 366 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 367 | |
---|
[1846] | 368 | assertNull(symbolMap.getValue(createTask("symbol"))); |
---|
[1285] | 369 | } |
---|
| 370 | |
---|
| 371 | @Test |
---|
| 372 | public void testGetValue_2() { |
---|
[1846] | 373 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 374 | |
---|
[1846] | 375 | symbolMap.addSymbol(createTask("symbol1"), "value1"); |
---|
[1285] | 376 | |
---|
[1846] | 377 | assertNotNull(symbolMap.getValue(createTask("symbol1"))); |
---|
[1285] | 378 | } |
---|
| 379 | |
---|
| 380 | @Test |
---|
| 381 | public void testGetValue_3() { |
---|
[1846] | 382 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 383 | |
---|
[1846] | 384 | symbolMap.addSymbol(createTask("symbol1"), null); |
---|
[1285] | 385 | |
---|
[1846] | 386 | assertNull(symbolMap.getValue(createTask("symbol1"))); |
---|
[1285] | 387 | } |
---|
| 388 | |
---|
| 389 | @Test |
---|
| 390 | public void testGetValue_4() { |
---|
[1846] | 391 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 392 | |
---|
| 393 | int entryCount = 2000; |
---|
| 394 | |
---|
| 395 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 396 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 397 | } |
---|
| 398 | |
---|
| 399 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 400 | assertNotNull(symbolMap.getValue(createTask("symbol" + i))); |
---|
[1285] | 401 | } |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | @Test |
---|
| 405 | public void testGetValue_5() { |
---|
[1846] | 406 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 407 | |
---|
| 408 | int entryCount = 2000; |
---|
| 409 | |
---|
| 410 | for (int i = 0; i < entryCount; i++) { |
---|
| 411 | if (i % 7 == 0) { |
---|
[1846] | 412 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 413 | } |
---|
| 414 | else { |
---|
[1846] | 415 | symbolMap.addSymbol(createTask("symbol" + i), null); |
---|
[1285] | 416 | } |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | for (int i = 0; i < entryCount; i++) { |
---|
| 420 | if (i % 7 == 0) { |
---|
[1846] | 421 | assertNotNull(symbolMap.getValue(createTask("symbol" + i))); |
---|
[1285] | 422 | } |
---|
| 423 | else { |
---|
[1846] | 424 | assertNull(symbolMap.getValue(createTask("symbol" + i))); |
---|
[1285] | 425 | } |
---|
| 426 | } |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | @Test |
---|
| 430 | public void testGetValue_6() { |
---|
[1846] | 431 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 432 | |
---|
| 433 | int entryCount = 2000; |
---|
| 434 | |
---|
| 435 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 436 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 437 | } |
---|
| 438 | |
---|
| 439 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 440 | symbolMap.removeSymbol(createTask("symbol" + i)); |
---|
[1285] | 441 | } |
---|
| 442 | |
---|
| 443 | for (int i = 0; i < 150; i++) { |
---|
[1846] | 444 | assertNotNull(symbolMap.getValue(createTask("symbol" + i))); |
---|
[1285] | 445 | } |
---|
| 446 | |
---|
| 447 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 448 | assertNull(symbolMap.getValue(createTask("symbol" + i))); |
---|
[1285] | 449 | } |
---|
| 450 | |
---|
| 451 | for (int i = (entryCount - 150); i < entryCount; i++) { |
---|
[1846] | 452 | assertNotNull(symbolMap.getValue(createTask("symbol" + i))); |
---|
[1285] | 453 | } |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
| 457 | public void testGetValue_7() { |
---|
[1846] | 458 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 459 | |
---|
| 460 | symbolMap.getValue(null); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | @Test |
---|
| 464 | public void testRemoveSymbol_1() { |
---|
[1846] | 465 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 466 | |
---|
[1846] | 467 | assertNull(symbolMap.removeSymbol(createTask("symbol"))); |
---|
[1285] | 468 | } |
---|
| 469 | |
---|
| 470 | @Test |
---|
| 471 | public void testRemoveSymbol_2() { |
---|
[1846] | 472 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 473 | |
---|
[1846] | 474 | symbolMap.addSymbol(createTask("symbol1"), "value1"); |
---|
[1285] | 475 | |
---|
[1846] | 476 | assertNotNull(symbolMap.removeSymbol(createTask("symbol1"))); |
---|
[1285] | 477 | assertEquals(0, symbolMap.size()); |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | @Test |
---|
| 481 | public void testRemoveSymbol_3() { |
---|
[1846] | 482 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 483 | |
---|
[1846] | 484 | symbolMap.addSymbol(createTask("symbol1"), null); |
---|
[1285] | 485 | |
---|
[1846] | 486 | assertNull(symbolMap.removeSymbol(createTask("symbol1"))); |
---|
[1285] | 487 | assertEquals(0, symbolMap.size()); |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | @Test |
---|
| 491 | public void testRemoveSymbol_4() { |
---|
[1846] | 492 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 493 | |
---|
| 494 | int entryCount = 2000; |
---|
| 495 | |
---|
| 496 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 497 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 498 | } |
---|
| 499 | |
---|
| 500 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 501 | assertNotNull(symbolMap.removeSymbol(createTask("symbol" + i))); |
---|
[1285] | 502 | } |
---|
| 503 | |
---|
| 504 | assertEquals(0, symbolMap.size()); |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | @Test |
---|
| 508 | public void testRemoveSymbol_5() { |
---|
[1846] | 509 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 510 | |
---|
| 511 | int entryCount = 2000; |
---|
| 512 | |
---|
| 513 | for (int i = 0; i < entryCount; i++) { |
---|
| 514 | if (i % 7 == 0) { |
---|
[1846] | 515 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 516 | } |
---|
| 517 | else { |
---|
[1846] | 518 | symbolMap.addSymbol(createTask("symbol" + i), null); |
---|
[1285] | 519 | } |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | for (int i = 0; i < entryCount; i++) { |
---|
| 523 | if (i % 7 == 0) { |
---|
[1846] | 524 | assertNotNull(symbolMap.removeSymbol(createTask("symbol" + i))); |
---|
[1285] | 525 | } |
---|
| 526 | else { |
---|
[1846] | 527 | assertNull(symbolMap.removeSymbol(createTask("symbol" + i))); |
---|
[1285] | 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | assertEquals(0, symbolMap.size()); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | @Test |
---|
| 535 | public void testRemoveSymbol_6() { |
---|
[1846] | 536 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 537 | |
---|
| 538 | int entryCount = 2000; |
---|
| 539 | |
---|
| 540 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 541 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 542 | } |
---|
| 543 | |
---|
| 544 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 545 | symbolMap.removeSymbol(createTask("symbol" + i)); |
---|
[1285] | 546 | } |
---|
| 547 | |
---|
| 548 | for (int i = 0; i < 150; i++) { |
---|
[1846] | 549 | assertNotNull(symbolMap.removeSymbol(createTask("symbol" + i))); |
---|
[1285] | 550 | } |
---|
| 551 | |
---|
| 552 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 553 | assertNull(symbolMap.removeSymbol(createTask("symbol" + i))); |
---|
[1285] | 554 | } |
---|
| 555 | |
---|
| 556 | for (int i = (entryCount - 150); i < entryCount; i++) { |
---|
[1846] | 557 | assertNotNull(symbolMap.removeSymbol(createTask("symbol" + i))); |
---|
[1285] | 558 | } |
---|
| 559 | |
---|
| 560 | assertEquals(0, symbolMap.size()); |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
| 564 | public void testRemoveSymbol_7() { |
---|
[1846] | 565 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 566 | |
---|
| 567 | symbolMap.removeSymbol(null); |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | @Test |
---|
| 571 | public void testGetSymbols_1() { |
---|
[1846] | 572 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 573 | |
---|
| 574 | assertNotNull(symbolMap.getSymbols()); |
---|
| 575 | assertEquals(0, symbolMap.getSymbols().size()); |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | @Test |
---|
| 579 | public void testGetSymbols_2() { |
---|
[1846] | 580 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 581 | |
---|
[1846] | 582 | ITask task = createTask("symbol1"); |
---|
[1285] | 583 | symbolMap.addSymbol(task, "value1"); |
---|
| 584 | |
---|
| 585 | assertNotNull(symbolMap.getSymbols()); |
---|
| 586 | assertEquals(1, symbolMap.getSymbols().size()); |
---|
| 587 | assertEquals(task, symbolMap.getSymbols().iterator().next()); |
---|
| 588 | } |
---|
| 589 | |
---|
| 590 | @Test |
---|
| 591 | public void testGetSymbols_3() { |
---|
[1846] | 592 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 593 | |
---|
[1846] | 594 | ITask task = createTask("symbol1"); |
---|
[1285] | 595 | symbolMap.addSymbol(task, null); |
---|
| 596 | |
---|
| 597 | assertNotNull(symbolMap.getSymbols()); |
---|
| 598 | assertEquals(1, symbolMap.getSymbols().size()); |
---|
| 599 | assertEquals(task, symbolMap.getSymbols().iterator().next()); |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | @Test |
---|
| 603 | public void testGetSymbols_4() { |
---|
[1846] | 604 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
| 605 | Set<ITask> expectedSymbols = new HashSet<ITask>(); |
---|
[1285] | 606 | |
---|
| 607 | int entryCount = 2000; |
---|
| 608 | |
---|
| 609 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 610 | ITask task = createTask("symbol" + i); |
---|
[1285] | 611 | symbolMap.addSymbol(task, "value" + i); |
---|
| 612 | expectedSymbols.add(task); |
---|
| 613 | } |
---|
| 614 | |
---|
| 615 | assertNotNull(symbolMap.getSymbols()); |
---|
| 616 | assertEquals(entryCount, symbolMap.getSymbols().size()); |
---|
| 617 | |
---|
[1846] | 618 | Iterator<ITask> iterator = symbolMap.getSymbols().iterator(); |
---|
[1285] | 619 | for (int i = 0; i < entryCount; i++) { |
---|
| 620 | assertTrue(iterator.hasNext()); |
---|
| 621 | expectedSymbols.remove(iterator.next()); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | assertTrue(expectedSymbols.isEmpty()); |
---|
| 625 | assertFalse(iterator.hasNext()); |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | @Test |
---|
| 629 | public void testGetSymbols_5() { |
---|
[1846] | 630 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
| 631 | Set<ITask> expectedSymbols = new HashSet<ITask>(); |
---|
[1285] | 632 | |
---|
| 633 | int entryCount = 2000; |
---|
| 634 | |
---|
| 635 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 636 | ITask task = createTask("symbol" + i); |
---|
[1285] | 637 | |
---|
| 638 | if (i % 7 == 0) { |
---|
| 639 | symbolMap.addSymbol(task, "value" + i); |
---|
| 640 | } |
---|
| 641 | else { |
---|
| 642 | symbolMap.addSymbol(task, null); |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | expectedSymbols.add(task); |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | assertNotNull(symbolMap.getSymbols()); |
---|
| 649 | assertEquals(entryCount, symbolMap.getSymbols().size()); |
---|
| 650 | |
---|
[1846] | 651 | Iterator<ITask> iterator = symbolMap.getSymbols().iterator(); |
---|
[1285] | 652 | for (int i = 0; i < entryCount; i++) { |
---|
| 653 | assertTrue(iterator.hasNext()); |
---|
| 654 | expectedSymbols.remove(iterator.next()); |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | assertTrue(expectedSymbols.isEmpty()); |
---|
| 658 | assertFalse(iterator.hasNext()); |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | @Test |
---|
| 662 | public void testGetSymbols_6() { |
---|
[1846] | 663 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
| 664 | List<ITask> expectedSymbols = new ArrayList<ITask>(); |
---|
[1285] | 665 | |
---|
| 666 | int entryCount = 2000; |
---|
| 667 | |
---|
| 668 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 669 | ITask task = createTask("symbol" + i); |
---|
[1285] | 670 | symbolMap.addSymbol(task, "value" + i); |
---|
| 671 | expectedSymbols.add(task); |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
| 675 | symbolMap.removeSymbol(expectedSymbols.remove(150)); |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | assertNotNull(symbolMap.getSymbols()); |
---|
| 679 | assertEquals(2 * 150, symbolMap.getSymbols().size()); |
---|
| 680 | |
---|
[1846] | 681 | Iterator<ITask> iterator = symbolMap.getSymbols().iterator(); |
---|
[1285] | 682 | for (int i = 0; i < 2 * 150; i++) { |
---|
| 683 | assertTrue(iterator.hasNext()); |
---|
| 684 | expectedSymbols.remove(iterator.next()); |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | assertTrue(expectedSymbols.isEmpty()); |
---|
| 688 | assertFalse(iterator.hasNext()); |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | @Test |
---|
| 692 | public void testGetValues_1() { |
---|
[1846] | 693 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 694 | |
---|
| 695 | assertNotNull(symbolMap.getValues()); |
---|
| 696 | assertEquals(0, symbolMap.getValues().size()); |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | @Test |
---|
| 700 | public void testGetValues_2() { |
---|
[1846] | 701 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 702 | |
---|
[1846] | 703 | symbolMap.addSymbol(createTask("symbol1"), "value1"); |
---|
[1285] | 704 | |
---|
| 705 | assertNotNull(symbolMap.getValues()); |
---|
| 706 | assertEquals(1, symbolMap.getValues().size()); |
---|
| 707 | assertEquals("value1", symbolMap.getValues().iterator().next()); |
---|
| 708 | } |
---|
| 709 | |
---|
| 710 | @Test |
---|
| 711 | public void testGetValues_3() { |
---|
[1846] | 712 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 713 | |
---|
[1846] | 714 | symbolMap.addSymbol(createTask("symbol1"), null); |
---|
[1285] | 715 | |
---|
| 716 | assertNotNull(symbolMap.getValues()); |
---|
| 717 | assertEquals(1, symbolMap.getValues().size()); |
---|
| 718 | assertNull(symbolMap.getValues().iterator().next()); |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | @Test |
---|
| 722 | public void testGetValues_4() { |
---|
[1846] | 723 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 724 | Set<String> expectedValues = new HashSet<String>(); |
---|
| 725 | |
---|
| 726 | int entryCount = 2000; |
---|
| 727 | |
---|
| 728 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 729 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 730 | expectedValues.add("value" + i); |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | assertNotNull(symbolMap.getValues()); |
---|
| 734 | assertEquals(entryCount, symbolMap.getValues().size()); |
---|
| 735 | |
---|
| 736 | Iterator<String> iterator = symbolMap.getValues().iterator(); |
---|
| 737 | for (int i = 0; i < entryCount; i++) { |
---|
| 738 | assertTrue(iterator.hasNext()); |
---|
| 739 | expectedValues.remove(iterator.next()); |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | assertTrue(expectedValues.isEmpty()); |
---|
| 743 | assertFalse(iterator.hasNext()); |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | @Test |
---|
| 747 | public void testGetValues_5() { |
---|
[1846] | 748 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 749 | Set<String> expectedValues = new HashSet<String>(); |
---|
| 750 | |
---|
| 751 | int entryCount = 2000; |
---|
| 752 | |
---|
| 753 | for (int i = 0; i < entryCount; i++) { |
---|
| 754 | if (i % 7 == 0) { |
---|
[1846] | 755 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 756 | expectedValues.add("value" + i); |
---|
| 757 | } |
---|
| 758 | else { |
---|
[1846] | 759 | symbolMap.addSymbol(createTask("symbol" + i), null); |
---|
[1285] | 760 | expectedValues.add(null); |
---|
| 761 | } |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | assertNotNull(symbolMap.getValues()); |
---|
| 765 | assertEquals(entryCount, symbolMap.getValues().size()); |
---|
| 766 | |
---|
| 767 | Iterator<String> iterator = symbolMap.getValues().iterator(); |
---|
| 768 | for (int i = 0; i < entryCount; i++) { |
---|
| 769 | assertTrue(iterator.hasNext()); |
---|
| 770 | expectedValues.remove(iterator.next()); |
---|
| 771 | } |
---|
| 772 | |
---|
| 773 | assertTrue(expectedValues.isEmpty()); |
---|
| 774 | assertFalse(iterator.hasNext()); |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | @Test |
---|
| 778 | public void testGetValues_6() { |
---|
[1846] | 779 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 780 | Set<String> expectedValues = new HashSet<String>(); |
---|
| 781 | |
---|
| 782 | int entryCount = 2000; |
---|
| 783 | |
---|
| 784 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 785 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 786 | expectedValues.add("value" + i); |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 790 | symbolMap.removeSymbol(createTask("symbol" + i)); |
---|
[1285] | 791 | expectedValues.remove("value" + i); |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | assertNotNull(symbolMap.getValues()); |
---|
| 795 | assertEquals(2 * 150, symbolMap.getValues().size()); |
---|
| 796 | |
---|
| 797 | Iterator<String> iterator = symbolMap.getValues().iterator(); |
---|
| 798 | for (int i = 0; i < 2 * 150; i++) { |
---|
| 799 | assertTrue(iterator.hasNext()); |
---|
| 800 | expectedValues.remove(iterator.next()); |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | assertTrue(expectedValues.isEmpty()); |
---|
| 804 | assertFalse(iterator.hasNext()); |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | @Test |
---|
| 808 | public void testClear_1() { |
---|
[1846] | 809 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 810 | |
---|
| 811 | symbolMap.clear(); |
---|
| 812 | assertEquals(0, symbolMap.getValues().size()); |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | @Test |
---|
| 816 | public void testClear_2() { |
---|
[1846] | 817 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 818 | |
---|
[1846] | 819 | symbolMap.addSymbol(createTask("symbol1"), "value1"); |
---|
[1285] | 820 | |
---|
| 821 | symbolMap.clear(); |
---|
| 822 | assertEquals(0, symbolMap.getValues().size()); |
---|
| 823 | } |
---|
| 824 | |
---|
| 825 | @Test |
---|
| 826 | public void testClear_3() { |
---|
[1846] | 827 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 828 | |
---|
[1846] | 829 | symbolMap.addSymbol(createTask("symbol1"), null); |
---|
[1285] | 830 | |
---|
| 831 | symbolMap.clear(); |
---|
| 832 | assertEquals(0, symbolMap.getValues().size()); |
---|
| 833 | } |
---|
| 834 | |
---|
| 835 | @Test |
---|
| 836 | public void testClear_4() { |
---|
[1846] | 837 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 838 | |
---|
| 839 | int entryCount = 2000; |
---|
| 840 | |
---|
| 841 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 842 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 843 | } |
---|
| 844 | |
---|
| 845 | symbolMap.clear(); |
---|
| 846 | assertEquals(0, symbolMap.getValues().size()); |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | @Test |
---|
| 850 | public void testClear_5() { |
---|
[1846] | 851 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 852 | |
---|
| 853 | int entryCount = 2000; |
---|
| 854 | |
---|
| 855 | for (int i = 0; i < entryCount; i++) { |
---|
| 856 | if (i % 7 == 0) { |
---|
[1846] | 857 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 858 | } |
---|
| 859 | else { |
---|
[1846] | 860 | symbolMap.addSymbol(createTask("symbol" + i), null); |
---|
[1285] | 861 | } |
---|
| 862 | } |
---|
| 863 | |
---|
| 864 | symbolMap.clear(); |
---|
| 865 | assertEquals(0, symbolMap.getValues().size()); |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | @Test |
---|
| 869 | public void testClear_6() { |
---|
[1846] | 870 | SymbolMap<ITask, String> symbolMap = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 871 | |
---|
| 872 | int entryCount = 2000; |
---|
| 873 | |
---|
| 874 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 875 | symbolMap.addSymbol(createTask("symbol" + i), "value" + i); |
---|
[1285] | 876 | } |
---|
| 877 | |
---|
| 878 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 879 | symbolMap.removeSymbol(createTask("symbol" + i)); |
---|
[1285] | 880 | } |
---|
| 881 | |
---|
| 882 | symbolMap.clear(); |
---|
| 883 | assertEquals(0, symbolMap.getValues().size()); |
---|
| 884 | } |
---|
| 885 | |
---|
| 886 | @Test |
---|
| 887 | public void testEquals_1() { |
---|
[1846] | 888 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 889 | |
---|
[1846] | 890 | SymbolMap<ITask, String> symbolMap2 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 891 | |
---|
| 892 | assertTrue(symbolMap1.equals(symbolMap2)); |
---|
| 893 | } |
---|
| 894 | |
---|
| 895 | @Test |
---|
| 896 | public void testEquals_2() { |
---|
[1846] | 897 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 898 | |
---|
[1846] | 899 | SymbolMap<ITask, String> symbolMap2 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 900 | |
---|
[1846] | 901 | symbolMap1.addSymbol(createTask("symbol1"), "value1"); |
---|
[1285] | 902 | |
---|
| 903 | assertFalse(symbolMap1.equals(symbolMap2)); |
---|
| 904 | } |
---|
| 905 | |
---|
| 906 | @Test |
---|
| 907 | public void testEquals_3() { |
---|
[1846] | 908 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 909 | |
---|
[1846] | 910 | SymbolMap<ITask, String> symbolMap2 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 911 | |
---|
[1846] | 912 | ITask task = createTask("symbol1"); |
---|
[1285] | 913 | symbolMap1.addSymbol(task, "value1"); |
---|
| 914 | symbolMap2.addSymbol(task, "value1"); |
---|
| 915 | |
---|
| 916 | assertTrue(symbolMap1.equals(symbolMap2)); |
---|
| 917 | } |
---|
| 918 | |
---|
| 919 | @Test |
---|
| 920 | public void testEquals_4() { |
---|
[1846] | 921 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 922 | |
---|
[1846] | 923 | SymbolMap<ITask, String> symbolMap2 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 924 | |
---|
| 925 | int entryCount = 1000; |
---|
| 926 | |
---|
| 927 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 928 | ITask task = createTask("symbol1"); |
---|
[1285] | 929 | symbolMap1.addSymbol(task, "value" + i); |
---|
| 930 | assertFalse(symbolMap1.equals(symbolMap2)); |
---|
| 931 | symbolMap2.addSymbol(task, "value" + i); |
---|
| 932 | assertTrue(symbolMap1.equals(symbolMap2)); |
---|
| 933 | } |
---|
| 934 | } |
---|
| 935 | |
---|
| 936 | @Test |
---|
| 937 | public void testEquals_5() { |
---|
[1846] | 938 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 939 | |
---|
[1846] | 940 | SymbolMap<ITask, String> symbolMap2 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 941 | |
---|
| 942 | int entryCount = 1000; |
---|
| 943 | |
---|
| 944 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 945 | ITask task = createTask("symbol" + i); |
---|
[1285] | 946 | if (i % 7 == 0) { |
---|
| 947 | symbolMap1.addSymbol(task, "value" + i); |
---|
| 948 | assertFalse(symbolMap1.equals(symbolMap2)); |
---|
| 949 | symbolMap2.addSymbol(task, "value" + i); |
---|
| 950 | assertTrue(symbolMap1.equals(symbolMap2)); |
---|
| 951 | } |
---|
| 952 | else { |
---|
| 953 | symbolMap1.addSymbol(task, null); |
---|
| 954 | assertFalse(symbolMap1.equals(symbolMap2)); |
---|
| 955 | symbolMap2.addSymbol(task, null); |
---|
| 956 | assertTrue(symbolMap1.equals(symbolMap2)); |
---|
| 957 | } |
---|
| 958 | } |
---|
| 959 | } |
---|
| 960 | |
---|
| 961 | @Test |
---|
| 962 | public void testEquals_6() { |
---|
[1846] | 963 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 964 | |
---|
[1846] | 965 | SymbolMap<ITask, String> symbolMap2 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 966 | |
---|
| 967 | int entryCount = 1000; |
---|
| 968 | |
---|
[1846] | 969 | ITask[] tasks = new ITask[entryCount]; |
---|
[1285] | 970 | |
---|
| 971 | for (int i = 0; i < entryCount; i++) { |
---|
[1846] | 972 | ITask task = createTask("symbol" + i); |
---|
| 973 | tasks[i] = task; |
---|
[1285] | 974 | symbolMap1.addSymbol(task, "value" + i); |
---|
| 975 | assertFalse(symbolMap1.equals(symbolMap2)); |
---|
| 976 | symbolMap2.addSymbol(task, "value" + i); |
---|
| 977 | assertTrue(symbolMap1.equals(symbolMap2)); |
---|
| 978 | } |
---|
| 979 | |
---|
| 980 | for (int i = 150; i < (entryCount - 150); i++) { |
---|
[1846] | 981 | symbolMap1.removeSymbol(tasks[i]); |
---|
[1285] | 982 | assertFalse(symbolMap1.equals(symbolMap2)); |
---|
[1846] | 983 | symbolMap2.removeSymbol(tasks[i]); |
---|
[1285] | 984 | assertTrue(symbolMap1.equals(symbolMap2)); |
---|
| 985 | } |
---|
| 986 | } |
---|
| 987 | |
---|
| 988 | @Test |
---|
| 989 | public void testPerformance_Contains_1() { |
---|
[1846] | 990 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 991 | int mapSize = 100000; |
---|
| 992 | int noOfLookups = 1000000; |
---|
| 993 | |
---|
[1846] | 994 | ITask[] tasks = new ITask[mapSize]; |
---|
[1285] | 995 | |
---|
| 996 | for (int i = 0; i < mapSize; i++) { |
---|
[1846] | 997 | ITask task = createTask("symbol" + i); |
---|
| 998 | tasks[i] = task; |
---|
[1285] | 999 | symbolMap1.addSymbol(task, "value" + i); |
---|
| 1000 | } |
---|
| 1001 | |
---|
| 1002 | long start = System.currentTimeMillis(); |
---|
| 1003 | for (int i = 0; i < noOfLookups; i++) { |
---|
[1846] | 1004 | symbolMap1.containsSymbol(tasks[noOfLookups % mapSize]); |
---|
[1285] | 1005 | } |
---|
| 1006 | |
---|
| 1007 | System.out.println(noOfLookups + " look ups in a map of size " + mapSize + " took " + |
---|
| 1008 | (System.currentTimeMillis() - start)); |
---|
| 1009 | } |
---|
| 1010 | |
---|
| 1011 | @Test |
---|
| 1012 | public void testPerformance_GetValue_1() { |
---|
[1846] | 1013 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 1014 | int mapSize = 100000; |
---|
| 1015 | int noOfLookups = 1000000; |
---|
| 1016 | |
---|
[1846] | 1017 | ITask[] tasks = new ITask[mapSize]; |
---|
[1285] | 1018 | |
---|
| 1019 | for (int i = 0; i < mapSize; i++) { |
---|
[1846] | 1020 | ITask task = createTask("symbol" + i); |
---|
| 1021 | tasks[i] = task; |
---|
[1285] | 1022 | symbolMap1.addSymbol(task, "value" + i); |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | long start = System.currentTimeMillis(); |
---|
| 1026 | for (int i = 0; i < noOfLookups; i++) { |
---|
[1846] | 1027 | symbolMap1.getValue(tasks[noOfLookups % mapSize]); |
---|
[1285] | 1028 | } |
---|
| 1029 | |
---|
| 1030 | System.out.println(noOfLookups + " value retrievals in a map of size " + mapSize + |
---|
| 1031 | " took " + (System.currentTimeMillis() - start)); |
---|
| 1032 | } |
---|
| 1033 | |
---|
| 1034 | |
---|
| 1035 | @Test |
---|
| 1036 | public void testPerformance_AddRemove_1() { |
---|
[1846] | 1037 | SymbolMap<ITask, String> symbolMap1 = new TaskSymbolIdentityMap<String>(); |
---|
[1285] | 1038 | int mapSize = 100000; |
---|
| 1039 | int noOfLookups = 1000000; |
---|
| 1040 | |
---|
[1846] | 1041 | ITask[] tasks = new ITask[mapSize]; |
---|
[1285] | 1042 | |
---|
| 1043 | for (int i = 0; i < mapSize; i++) { |
---|
[1846] | 1044 | ITask task = createTask("symbol" + i); |
---|
| 1045 | tasks[i] = task; |
---|
[1285] | 1046 | symbolMap1.addSymbol(task, "value" + i); |
---|
| 1047 | } |
---|
| 1048 | |
---|
| 1049 | long start = System.currentTimeMillis(); |
---|
| 1050 | for (int i = 0; i < noOfLookups; i++) { |
---|
[1846] | 1051 | ITask task = tasks[noOfLookups % mapSize]; |
---|
[1285] | 1052 | symbolMap1.addSymbol(task, symbolMap1.removeSymbol(task)); |
---|
| 1053 | } |
---|
| 1054 | |
---|
| 1055 | System.out.println(noOfLookups + " adds and removes in a map of size " + mapSize + |
---|
| 1056 | " took " + (System.currentTimeMillis() - start)); |
---|
| 1057 | } |
---|
[1294] | 1058 | |
---|
[1285] | 1059 | /** |
---|
| 1060 | * |
---|
| 1061 | */ |
---|
[1846] | 1062 | private ITask createTask(String id) { |
---|
[1285] | 1063 | ITask task = tasks.get(id); |
---|
[1294] | 1064 | Event event = null; |
---|
[1285] | 1065 | |
---|
| 1066 | if (task == null) { |
---|
[1294] | 1067 | event = new Event(new DummyInteraction(id, 0), new DummyGUIElement("default")); |
---|
| 1068 | task = taskFactory.createNewEventTask(event.toString()); |
---|
[1285] | 1069 | |
---|
| 1070 | tasks.put(id, task); |
---|
| 1071 | } |
---|
[1294] | 1072 | else { |
---|
| 1073 | event = ((IEventTaskInstance) task.getInstances().iterator().next()).getEvent(); |
---|
| 1074 | } |
---|
[1285] | 1075 | |
---|
[1846] | 1076 | taskFactory.createNewTaskInstance((IEventTask) task, event); |
---|
| 1077 | |
---|
| 1078 | return task; |
---|
[1285] | 1079 | } |
---|
| 1080 | |
---|
[1846] | 1081 | private void assertSymbolMapEntries(SymbolMap<ITask, String> symbolMap, |
---|
| 1082 | ITask[] symbols, |
---|
| 1083 | String[] values) |
---|
[1285] | 1084 | { |
---|
| 1085 | assertEquals(symbols.length, symbolMap.size()); |
---|
| 1086 | assertEquals(symbols.length, symbolMap.getSymbols().size()); |
---|
| 1087 | assertEquals(values.length, symbolMap.getValues().size()); |
---|
| 1088 | |
---|
| 1089 | for (int i = 0; i < symbols.length; i++) { |
---|
| 1090 | assertTrue(symbolMap.containsSymbol(symbols[i])); |
---|
| 1091 | assertEquals(values[i], symbolMap.getValue(symbols[i])); |
---|
| 1092 | assertTrue(symbolMap.getSymbols().contains(symbols[i])); |
---|
| 1093 | assertTrue(symbolMap.getValues().contains(values[i])); |
---|
| 1094 | } |
---|
| 1095 | } |
---|
| 1096 | } |
---|