Libraryless. Click here for Pure Java version (5918L/37K).
// pass an empty instance svoid test_List(L<S> l, O... _) { // Simple test optPar int n = 1000; optPar int idLength = 5; assertEqualsVerbose(0, l.size()); for (int i = -1; i < 2; i++) { int _i = i ; assertException(r { l.get(_i) }); } l.add("hello"); assertEqualsVerbose(1, l.size()); assertException(r { l.get(-1) }); assertEqualsVerbose("hello", l.get(0)); assertException(r { l.get(1) }); Random random = predictableRandom(); // 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); 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)); } // 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)); for j over refl: assertEquals(l.get(j), refl.get(j)); } test_List_2(l, _); infoBox(className(l) + " works (tested up to size " + n + ")! :)"); }
Began life as a copy of #1024414
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1025482 |
Snippet name: | test_List - test general functions of a List implementation |
Eternal ID of this version: | #1025482/2 |
Text MD5: | 888045bbabb847ca281de8e141f8decc |
Transpilation MD5: | 0582a6b144a5adaf42a6bc1e54212f89 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-30 22:24:45 |
Source code size: | 1491 bytes / 56 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 237 / 319 |
Version history: | 1 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1025485 - test_List_2 - more tests for a list (called by test_List) #1031665 - ListTester - successor of test_List - test general functions of a List implementation |