// pass an empty instance sclass MapTester { SS map; *(SS *map) {} *(SS *map, IF1 *rotate) {} // parameters int n = 1000; int idLength = 5; // optional rotation to/from storage int rotateAtLeastEvery = 20; swappable SS rotate(SS map) { ret map; } // output int rotationsDone; // internal int rotCountdown; Random random = predictableRandom(); // Simple test run { assertEqualsVerbose(0, map.size()); for (int i = -1; i < 2; i++) { int _i = i ; assertException(r { map.get(_i) }); } map.add("hello"); rot(); assertEqualsVerbose(1, map.size()); assertException(r { map.get(-1) }); assertEqualsVerbose("hello", map.get(0)); assertException(r { map.get(1) }); // n random insertions, complete check new SS refl; map.clear(); repeat n { int i = random(random, l(refl)+1); S id = randomID(random, idLength); print("add " + i + " " + id); refl.add(i, id); map.add(i, id); rot(); assertEquals(l(map), l(refl)); } assertEqualsVerbose(l(map), l(refl)); for i over refl: assertEquals(map.get(i), refl.get(i)); // overwriting repeat n { int i = random(random, l(refl)); S id = randomID(random); print("set " + i + " " + id); assertEquals(map.set(i, id), refl.set(i, id)); assertEquals(l(map), l(refl)); rot(); } // n random deletions, check after each turn repeat n { int i = random(random, l(refl)); print("remove " + i); assertEquals(map.remove(i), refl.remove(i)); assertEqualsVerbose(l(map), l(refl)); rot(); for j over refl: assertEquals(map.get(j), refl.get(j)); } } void ok { infoBox(className(map) + " works (tested up to size " + n + ")! :)"); } void rot { if (rotCountdown <= 0) rotCountdown = random(random, rotateAtLeastEvery)+1; if (--rotCountdown <= 0) { map = rotate(map); rotationsDone++; } } }