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
144 lines (129 loc) · 5.18 KB
/
Copy pathSkippableBasicTest.java
File metadata and controls
144 lines (129 loc) · 5.18 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package me.lemire.integercompression;
import java.util.Arrays;
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 NewPFD(), new VariableByte()),
new SkippableComposition(new NewPFDS9(), new VariableByte()),
new SkippableComposition(new NewPFDS16(), new VariableByte()),
new SkippableComposition(new OptPFD(), new VariableByte()),
new SkippableComposition(new OptPFDS9(), new VariableByte()),
new SkippableComposition(new OptPFDS16(), new VariableByte()),
new SkippableComposition(new FastPFOR128(), new VariableByte()),
new SkippableComposition(new FastPFOR(), new VariableByte()),
new Simple9(),
new Simple16() };
/**
*
*/
@Test
public void consistentTest() {
int N = 4096;
int[] data = new int[N];
int[] rev = new int[N];
for (int k = 0; k < N; ++k)
data[k] = k % 128;
for (SkippableIntegerCODEC c : codecs) {
System.out.println("[SkippeableBasicTest.consistentTest] codec = "
+ c);
int[] outBuf = new int[N + 1024];
for (int n = 0; n <= N; ++n) {
IntWrapper inPos = new IntWrapper();
IntWrapper outPos = new IntWrapper();
c.headlessCompress(data, inPos, n, outBuf, outPos);
IntWrapper inPoso = new IntWrapper();
IntWrapper outPoso = new IntWrapper();
c.headlessUncompress(outBuf, inPoso, outPos.get(), rev,
outPoso, n);
if (outPoso.get() != n) {
throw new RuntimeException("bug "+n);
}
if (inPoso.get() != outPos.get()) {
throw new RuntimeException("bug "+n+" "+inPoso.get()+" "+outPos.get());
}
for (int j = 0; j < n; ++j)
if (data[j] != rev[j]) {
throw new RuntimeException("bug");
}
}
}
}
/**
*
*/
@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) {
System.out.println("[SkippeableBasicTest.varyingLengthTest] codec = "+c);
for (int L = 1; L <= 128; L++) {
int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
int[] answer = TestUtils.uncompressHeadless(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.compressHeadless(c, Arrays.copyOf(data, L));
int[] answer = TestUtils.uncompressHeadless(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) {
System.out.println("[SkippeableBasicTest.varyingLengthTest2] codec = "+c);
try {
// CODEC Simple9 is limited to "small" integers.
if (c.getClass().equals(
Class.forName("me.lemire.integercompression.Simple9")))
continue;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
// CODEC Simple16 is limited to "small" integers.
if (c.getClass().equals(
Class.forName("me.lemire.integercompression.Simple16")))
continue;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
for (int L = 1; L <= 128; L++) {
int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
int[] answer = TestUtils.uncompressHeadless(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.compressHeadless(c, Arrays.copyOf(data, L));
int[] answer = TestUtils.uncompressHeadless(c, comp, L);
for (int k = 0; k < L; ++k)
if (answer[k] != data[k])
throw new RuntimeException("bug");
}
}
}
}