forked from fast-pack/JavaFastPFOR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdhocTest.java
More file actions
156 lines (129 loc) · 5.16 KB
/
Copy pathAdhocTest.java
File metadata and controls
156 lines (129 loc) · 5.16 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
145
146
147
148
149
150
151
152
153
154
155
156
/**
* This code is released under the
* Apache License Version 2.0 http://www.apache.org/licenses/.
*
* (c) Daniel Lemire, http://lemire.me/en/
*/
package me.lemire.integercompression;
import org.junit.Assert;
import org.junit.Test;
import me.lemire.integercompression.differential.*;
import static me.lemire.integercompression.TestUtils.*;
import java.util.Arrays;
/**
* Collection of adhoc tests.
*/
@SuppressWarnings({ "static-method" })
public class AdhocTest {
@Test
public void testIssue59() {
FastPFOR128 fastpfor = new FastPFOR128();
int N = 9984;
int[] data = new int[N];
for (var i = 0; i < N; i += 150) {
data[i] = i;
}
int[] compressedoutput1 = new int[N + 1024];
IntWrapper inputoffset1 = new IntWrapper(0);
IntWrapper outputoffset1 = new IntWrapper(0);
fastpfor.compress(data, inputoffset1, N, compressedoutput1, outputoffset1);
int compressedsize1 = outputoffset1.get();
int[] recovered1 = new int[N];
inputoffset1 = new IntWrapper(0);
outputoffset1 = new IntWrapper(0);
fastpfor.uncompress(compressedoutput1, outputoffset1, compressedsize1, recovered1, inputoffset1);
Assert.assertArrayEquals(data, recovered1);
int[] compressedoutput2 = new int[N + 1024];
IntWrapper inputoffset2 = new IntWrapper(0);
IntWrapper outputoffset2 = new IntWrapper(0);
fastpfor.compress(data, inputoffset2, N, compressedoutput2, outputoffset2);
int compressedsize2 = outputoffset2.get();
int[] recovered2 = new int[N];
inputoffset2 = new IntWrapper(0);
outputoffset2 = new IntWrapper(0);
fastpfor.uncompress(compressedoutput2, outputoffset2, compressedsize2, recovered2, inputoffset2);
Assert.assertArrayEquals(data, recovered2);
}
@Test
public void testIssue29() {
for(int x = 0; x < 64; x++) {
int[] a = {2, 3, 4, 5};
int[] b = new int[90];
int[] c = new int[a.length];
IntegerCODEC codec = new Composition(new BinaryPacking(), new VariableByte());
IntWrapper aOffset = new IntWrapper(0);
IntWrapper bOffset = new IntWrapper(x);
codec.compress(a, aOffset, a.length, b, bOffset);
int len = bOffset.get() - x;
bOffset.set(x);
IntWrapper cOffset = new IntWrapper(0);
codec.uncompress(b, bOffset, len, c, cOffset);
Assert.assertArrayEquals(a,c);
}
}
/**
*
*/
@Test
public void testIssue29b() {
for(int x = 0; x < 64; x++) {
SkippableIntegerCODEC codec = new SkippableComposition(new BinaryPacking(), new VariableByte());
int[] a = {2, 3, 4, 5};
int[] b = new int[x + codec.maxHeadlessCompressedLength(new IntWrapper(0), a.length)];
int[] c = new int[a.length];
IntWrapper aOffset = new IntWrapper(0);
IntWrapper bOffset = new IntWrapper(x);
codec.headlessCompress(a, aOffset, a.length, b, bOffset);
int len = bOffset.get() - x;
bOffset.set(x);
IntWrapper cOffset = new IntWrapper(0);
codec.headlessUncompress(b, bOffset, len, c, cOffset, a.length);
Assert.assertArrayEquals(a,c);
}
}
/**
*
*/
@Test
public void testIssue41() {
for (int x = 0; x < 64; x++) {
SkippableIntegratedIntegerCODEC codec = new SkippableIntegratedComposition(new IntegratedBinaryPacking(),
new IntegratedVariableByte());
int[] a = { 2, 3, 4, 5 };
int[] b = new int[x + codec.maxHeadlessCompressedLength(new IntWrapper(0), a.length)];
int[] c = new int[a.length];
IntWrapper aOffset = new IntWrapper(0);
IntWrapper bOffset = new IntWrapper(x);
IntWrapper initValue = new IntWrapper(0);
codec.headlessCompress(a, aOffset, a.length, b, bOffset, initValue);
int len = bOffset.get() - x;
bOffset.set(x);
IntWrapper cOffset = new IntWrapper(0);
initValue = new IntWrapper(0);
codec.headlessUncompress(b, bOffset, len, c, cOffset, a.length, initValue);
Assert.assertArrayEquals(a, c);
}
}
@Test
public void biggerCompressedArray0() {
// No problem: for comparison.
IntegerCODEC c = new Composition(new FastPFOR128(), new VariableByte());
assertSymmetry(c, 0, 16384);
c = new Composition(new FastPFOR(), new VariableByte());
assertSymmetry(c, 0, 16384);
}
@Test
public void biggerCompressedArray1() {
// Compressed array is bigger than original, because of VariableByte.
IntegerCODEC c = new VariableByte();
assertSymmetry(c, -1);
}
@Test
public void biggerCompressedArray2() {
// Compressed array is bigger than original, because of Composition.
IntegerCODEC c = new Composition(new FastPFOR128(), new VariableByte());
assertSymmetry(c, 65535, 65535);
c = new Composition(new FastPFOR(), new VariableByte());
assertSymmetry(c, 65535, 65535);
}
}