forked from fast-pack/JavaFastPFOR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundaryTest.java
More file actions
68 lines (57 loc) · 2.01 KB
/
Copy pathBoundaryTest.java
File metadata and controls
68 lines (57 loc) · 2.01 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
package me.lemire.integercompression;
import java.util.Arrays;
import org.junit.Test;
import static org.junit.Assert.*;
public class BoundaryTest
{
private static void compressAndUncompress(int length, IntegerCODEC c) {
// Initialize array.
int[] source = new int[length];
for (int i = 0; i < source.length; ++i) {
source[i] = i;
}
// Compress an array.
int[] compressed = new int[length];
IntWrapper c_inpos = new IntWrapper(0);
IntWrapper c_outpos = new IntWrapper(0);
c.compress(source, c_inpos, source.length, compressed, c_outpos);
assertTrue(c_outpos.get() <= length);
// Uncompress an array.
int[] uncompressed = new int[length];
IntWrapper u_inpos = new IntWrapper(0);
IntWrapper u_outpos = new IntWrapper(0);
c.uncompress(compressed, u_inpos, c_outpos.get(),
uncompressed, u_outpos);
// Compare between uncompressed and original arrays.
int[] target = Arrays.copyOf(uncompressed, u_outpos.get());
assertArrayEquals(source, target);
}
private static void around128(IntegerCODEC c) {
compressAndUncompress(127, c);
compressAndUncompress(128, c);
compressAndUncompress(129, c);
}
private static void around256(IntegerCODEC c) {
compressAndUncompress(255, c);
compressAndUncompress(256, c);
compressAndUncompress(257, c);
}
private static void testBoundary(IntegerCODEC c) {
around128(c);
around256(c);
}
@Test
public void testIntegratedComposition() throws Exception {
IntegratedComposition c = new IntegratedComposition(
new IntegratedBinaryPacking(),
new IntegratedVariableByte());
testBoundary(c);
}
@Test
public void testComposition() throws Exception {
Composition c = new Composition(
new BinaryPacking(),
new VariableByte());
testBoundary(c);
}
}