Libraryless. Click here for Pure Java version (522L/4K).
set flag LeanMode.
svoid test_LogNArray() {
test_LogNArray(1000);
}
svoid test_LogNArray(int n) {
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));
}
System.out.println("LogNArray works (tested up to size " + n + ")! :)");
}
static int l(Collection l) { ret l == null ? 0 : l.size(); }
static int l(S s) { ret s == null ? 0 : s.length(); }
static <A> A print(A a) { System.out.println(a); ret a; }
static int random(Random r, int n) {
return n <= 0 ? 0 : r.nextInt(n);
}
svoid silentException(Throwable e) {}
do not include function add.
do not include function get.
do not include function set.
do not include function remove.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: | #1024445 |
| Snippet name: | test_LogNArray (for export) |
| Eternal ID of this version: | #1024445/11 |
| Text MD5: | c130fb0e8717e4831da2234abbbd9053 |
| Transpilation MD5: | 87e7ecdb98a058a6e457bfcc07690dbc |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-08-12 22:42:11 |
| Source code size: | 1878 bytes / 71 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 630 / 848 |
| Version history: | 10 change(s) |
| Referenced in: | -