Libraryless. Click here for Pure Java version (5918L/37K).
1 | // pass an empty instance |
2 | svoid test_List(L<S> l, O... _) { |
3 | // Simple test |
4 | |
5 | optPar int n = 1000; |
6 | optPar int idLength = 5; |
7 | |
8 | assertEqualsVerbose(0, l.size()); |
9 | for (int i = -1; i < 2; i++) { int _i = i ; assertException(r { l.get(_i) }); } |
10 | l.add("hello"); |
11 | assertEqualsVerbose(1, l.size()); |
12 | assertException(r { l.get(-1) }); |
13 | assertEqualsVerbose("hello", l.get(0)); |
14 | assertException(r { l.get(1) }); |
15 | |
16 | Random random = predictableRandom(); |
17 | |
18 | // n random insertions, complete check |
19 | |
20 | new LS refl; |
21 | l.clear(); |
22 | repeat n { |
23 | int i = random(random, l(refl)+1); |
24 | S id = randomID(random, idLength); |
25 | print("add " + i + " " + id); |
26 | refl.add(i, id); |
27 | l.add(i, id); |
28 | assertEquals(l(l), l(refl)); |
29 | } |
30 | assertEqualsVerbose(l(l), l(refl)); |
31 | for i over refl: |
32 | assertEquals(l.get(i), refl.get(i)); |
33 | |
34 | // overwriting |
35 | repeat n { |
36 | int i = random(random, l(refl)); |
37 | S id = randomID(random); |
38 | print("set " + i + " " + id); |
39 | assertEquals(l.set(i, id), refl.set(i, id)); |
40 | assertEquals(l(l), l(refl)); |
41 | } |
42 | |
43 | // n random deletions, check after each turn |
44 | repeat n { |
45 | int i = random(random, l(refl)); |
46 | print("remove " + i); |
47 | assertEquals(l.remove(i), refl.remove(i)); |
48 | assertEqualsVerbose(l(l), l(refl)); |
49 | for j over refl: |
50 | assertEquals(l.get(j), refl.get(j)); |
51 | } |
52 | |
53 | test_List_2(l, _); |
54 | |
55 | infoBox(className(l) + " works (tested up to size " + n + ")! :)"); |
56 | } |
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: | 236 / 319 |
Version history: | 1 change(s) |
Referenced in: | [show references] |