Libraryless. Click here for Pure Java version (14124L/97K).
//set flag LogNArray_debug. svoid test_LogNArray(O... _) { // Simple test optPar int n = 1000; new LogNArray<S> l; 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); 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)); } infoBox("LogNArray works (tested up to size " + n + ")! :)"); }
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: | #1024414 |
Snippet name: | test_LogNArray (OK) |
Eternal ID of this version: | #1024414/19 |
Text MD5: | b51616378c96adc9baa606bbd00d8119 |
Transpilation MD5: | c5393ced1a0bbf7cc0fe67c1617e28f6 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-08-12 14:02:53 |
Source code size: | 1445 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 293 / 473 |
Version history: | 18 change(s) |
Referenced in: | [show references] |