forked from fast-pack/JavaFastPFOR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourcedTest.java
More file actions
88 lines (78 loc) · 3.22 KB
/
Copy pathResourcedTest.java
File metadata and controls
88 lines (78 loc) · 3.22 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
/**
* 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 java.util.ArrayList;
import me.lemire.integercompression.differential.IntegratedIntCompressor;
import me.lemire.integercompression.differential.SkippableIntegratedIntegerCODEC;
import java.io.BufferedReader;
import java.io.File;
import org.junit.Assert;
import java.io.FileReader;
import java.io.IOException;
import org.junit.Test;
/**
* Tests with resources
*
*/
public class ResourcedTest {
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() };
/**
* @throws IOException
* if the resource cannot be accessed (should be considered a
* bug)
*
*/
@Test
public void IntCompressorTest() throws IOException {
// next line requires Java8?
// int[] data =
// Files.lines(Paths.get("integers.txt")).mapToInt(Integer::parseInt).toArray();
File f = new File("src/test/resources/integers.txt");
System.out.println("loading test data from "+ f.getAbsolutePath());
BufferedReader bfr = new BufferedReader(new FileReader(f));
String line;
ArrayList<Integer> ai = new ArrayList<Integer>();
while ((line = bfr.readLine()) != null) {
ai.add(Integer.parseInt(line));
}
bfr.close();
int[] data = new int[ai.size()];
for (int k = 0; k < data.length; ++k)
data[k] = ai.get(k).intValue();
ai = null;
// finally!
{
IntegratedIntCompressor iic = new IntegratedIntCompressor();
int[] compressed = iic.compress(data);
int[] recovered = iic.uncompress(compressed);
Assert.assertArrayEquals(recovered, data);
}
for (SkippableIntegerCODEC C : codecs) {
IntCompressor iic = new IntCompressor(C);
int[] compressed = iic.compress(data);
int[] recovered = iic.uncompress(compressed);
Assert.assertArrayEquals(recovered, data);
}
for (SkippableIntegerCODEC C : codecs) {
if (C instanceof SkippableIntegratedIntegerCODEC) {
IntegratedIntCompressor iic = new IntegratedIntCompressor((SkippableIntegratedIntegerCODEC) C);
int[] compressed = iic.compress(data);
int[] recovered = iic.uncompress(compressed);
Assert.assertArrayEquals(recovered, data);
}
}
}
}