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