forked from fast-pack/JavaFastPFOR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkippableBasicTest.java
More file actions
99 lines (88 loc) · 3.39 KB
/
Copy pathSkippableBasicTest.java
File metadata and controls
99 lines (88 loc) · 3.39 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package me.lemire.integercompression;
import java.util.Arrays;
import me.lemire.integercompression.skippable.*;
import org.junit.Test;
/**
* Just some basic sanity tests.
*
* @author Daniel Lemire
*/
@SuppressWarnings({ "static-method" })
public class SkippableBasicTest {
SkippableIntegerCODEC[] codecs = {
new JustCopy(),
new VariableByte(),
new SkippableComposition(new BinaryPacking(), new VariableByte()),
new SkippableComposition(new SkippableNewPFD(), new VariableByte()),
new SkippableComposition(new SkippableOptPFD(), new VariableByte()),
new SkippableComposition(new SkippableFastPFOR(), new VariableByte()),
new SkippableSimple9(),
new SkippableSimple16() };
/**
*
*/
@Test
public void varyingLengthTest() {
int N = 4096;
int[] data = new int[N];
for (int k = 0; k < N; ++k)
data[k] = k;
for (SkippableIntegerCODEC c : codecs) {
for (int L = 1; L <= 128; L++) {
int[] comp = TestUtils.compress(c, Arrays.copyOf(data, L));
int[] answer = TestUtils.uncompress(c, comp, L);
for (int k = 0; k < L; ++k)
if (answer[k] != data[k])
throw new RuntimeException("bug "+c.toString()+" "+k+" "+answer[k]+" "+data[k]);
}
for (int L = 128; L <= N; L *= 2) {
int[] comp = TestUtils.compress(c, Arrays.copyOf(data, L));
int[] answer = TestUtils.uncompress(c, comp, L);
for (int k = 0; k < L; ++k)
if (answer[k] != data[k])
throw new RuntimeException("bug");
}
}
}
/**
*
*/
@Test
public void varyingLengthTest2() {
int N = 128;
int[] data = new int[N];
data[127] = -1;
for (SkippableIntegerCODEC c : codecs) {
try {
// CODEC Simple9 is limited to "small" integers.
if (c.getClass().equals(
Class.forName("me.lemire.integercompression.skippable.SkippableSimple9")))
continue;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
// CODEC Simple16 is limited to "small" integers.
if (c.getClass().equals(
Class.forName("me.lemire.integercompression.skippable.SkippableSimple16")))
continue;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
for (int L = 1; L <= 128; L++) {
int[] comp = TestUtils.compress(c, Arrays.copyOf(data, L));
int[] answer = TestUtils.uncompress(c, comp, L);
for (int k = 0; k < L; ++k)
if (answer[k] != data[k])
throw new RuntimeException("bug at k = "+k+" "+answer[k]+" "+data[k]+" for "+c.toString());
}
for (int L = 128; L <= N; L *= 2) {
int[] comp = TestUtils.compress(c, Arrays.copyOf(data, L));
int[] answer = TestUtils.uncompress(c, comp, L);
for (int k = 0; k < L; ++k)
if (answer[k] != data[k])
throw new RuntimeException("bug");
}
}
}
}