Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

71
LINES

< > BotCompany Repo | #1024445 // test_LogNArray (for export)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (522L/4K).

1  
set flag LeanMode.
2  
3  
svoid test_LogNArray() {
4  
  test_LogNArray(1000);
5  
}
6  
7  
svoid test_LogNArray(int n) {
8  
  new LogNArray<S> l;
9  
  assertEqualsVerbose(0, l.size());
10  
  for (int i = -1; i < 2; i++) { int _i = i ; assertException(r { l.get(_i) }); }
11  
  l.add("hello");
12  
  assertEqualsVerbose(1, l.size());
13  
  assertException(r { l.get(-1) });
14  
  assertEqualsVerbose("hello", l.get(0));
15  
  assertException(r { l.get(1) });
16  
  
17  
  Random random = predictableRandom();
18  
  
19  
  // n random insertions, complete check
20  
  
21  
  new LS refl;
22  
  l.clear();
23  
  repeat n {
24  
    int i = random(random, l(refl)+1);
25  
    S id = randomID(random);
26  
    print("add " + i + " " + id);
27  
    refl.add(i, id);
28  
    l.add(i, id);
29  
    assertEquals(l(l), l(refl));
30  
  }
31  
  assertEqualsVerbose(l(l), l(refl));
32  
  for i over refl:
33  
    assertEquals(l.get(i), refl.get(i));
34  
    
35  
  // overwriting
36  
  repeat n {
37  
    int i = random(random, l(refl));
38  
    S id = randomID(random);
39  
    print("set " + i + " " + id);
40  
    assertEquals(l.set(i, id), refl.set(i, id));
41  
    assertEquals(l(l), l(refl));
42  
  }
43  
    
44  
  // n random deletions, check after each turn
45  
  repeat n {
46  
    int i = random(random, l(refl));
47  
    print("remove " + i);
48  
    assertEquals(l.remove(i), refl.remove(i));
49  
    assertEqualsVerbose(l(l), l(refl));
50  
    for j over refl:
51  
      assertEquals(l.get(j), refl.get(j));
52  
  }
53  
  
54  
  System.out.println("LogNArray works (tested up to size " + n + ")! :)");
55  
}
56  
57  
static int l(Collection l) { ret l == null ? 0 : l.size(); }
58  
static int l(S s) { ret s == null ? 0 : s.length(); }
59  
60  
static <A> A print(A a) { System.out.println(a); ret a; }
61  
62  
static int random(Random r, int n) {
63  
  return n <= 0 ? 0 : r.nextInt(n);
64  
}
65  
66  
svoid silentException(Throwable e) {}
67  
68  
do not include function add.
69  
do not include function get.
70  
do not include function set.
71  
do not include function remove.

Author comment

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: 220 / 343
Version history: 10 change(s)
Referenced in: [show references]