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

55
LINES

< > BotCompany Repo | #1024414 // test_LogNArray (OK)

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

Libraryless. Click here for Pure Java version (14124L/97K).

1  
//set flag LogNArray_debug.
2  
3  
svoid test_LogNArray(O... _) {
4  
  // Simple test
5  
  
6  
  optPar int n = 1000;
7  
  
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  
  infoBox("LogNArray works (tested up to size " + n + ")! :)");
55  
}

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: 295 / 477
Version history: 18 change(s)
Referenced in: [show references]