-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessCountArrayListTest.java
More file actions
executable file
·48 lines (43 loc) · 1.44 KB
/
AccessCountArrayListTest.java
File metadata and controls
executable file
·48 lines (43 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Random;
import java.util.*;
import java.util.zip.CRC32;
public strictfp class AccessCountArrayListTest {
private static int TRIALS = 10000;
private static int SEED = 87654;
private void updateCheck(double x, CRC32 check) {
long y = Double.doubleToRawLongBits(x);
check.update((int)(y & 0x0000FFFF));
check.update((int)(y >> 32));
}
@Test
public void massTest() {
AccessCountArrayList<Double> acad = new AccessCountArrayList<Double>();
Random rng = new Random(SEED);
CRC32 check = new CRC32();
int idx;
for(int i = 0; i < TRIALS; i++) {
acad.clear();
acad.resetCount();
int len = rng.nextInt(1000) + 50;
for(int j = 0; j < len; j++) {
acad.add(rng.nextDouble());
}
for(int j = 0; j < len; j++) {
if(rng.nextBoolean()) {
idx = rng.nextInt(len);
updateCheck(acad.set(idx, rng.nextDouble()), check);
}
if(rng.nextBoolean()) {
idx = rng.nextInt(len);
updateCheck(acad.get(idx), check);
}
check.update(acad.getAccessCount());
}
}
assertEquals(3163640888L, check.getValue());
}
}