aboutsummaryrefslogtreecommitdiff
path: root/test/ch/epfl
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-04-29 22:58:58 +0200
committerPacien TRAN-GIRARD2016-04-29 22:58:58 +0200
commit1fe15b896ede0882a0970602fea9d2e823b51095 (patch)
tree9418bc835082a64128def4af2efb6e12c22a1123 /test/ch/epfl
parentceb1ac5ca1e08095150c1dbb971540149a455673 (diff)
downloadxblast-1fe15b896ede0882a0970602fea9d2e823b51095.tar.gz
Implement RLE and its tests
Diffstat (limited to 'test/ch/epfl')
-rw-r--r--test/ch/epfl/xblast/RunLengthEncoderTest.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/test/ch/epfl/xblast/RunLengthEncoderTest.java b/test/ch/epfl/xblast/RunLengthEncoderTest.java
new file mode 100644
index 0000000..6880b99
--- /dev/null
+++ b/test/ch/epfl/xblast/RunLengthEncoderTest.java
@@ -0,0 +1,100 @@
1package ch.epfl.xblast;
2
3import org.junit.Test;
4
5import java.util.Arrays;
6import java.util.List;
7
8import static org.junit.Assert.assertEquals;
9
10/**
11 * @author Pacien TRAN-GIRARD (261948)
12 */
13public class RunLengthEncoderTest {
14
15 private static final Byte[] SAMPLE_PLAIN = {10, 10, 10, 20, 20, 30, 20, 30, 40, 40, 40, 40, 40, 40};
16 private static final Byte[] SAMPLE_ENCODED = {-1, 10, 20, 20, 30, 20, 30, -4, 40};
17 private static final RunLengthEncoder.RunLength[] SAMPLE_RUN_LENGTHS = {
18 new RunLengthEncoder.RunLength(3, (byte) 10),
19 new RunLengthEncoder.RunLength(2, (byte) 20),
20 new RunLengthEncoder.RunLength(1, (byte) 30),
21 new RunLengthEncoder.RunLength(1, (byte) 20),
22 new RunLengthEncoder.RunLength(1, (byte) 30),
23 new RunLengthEncoder.RunLength(6, (byte) 40)};
24
25 @Test
26 public void isSampleEncoded() {
27 List<Byte> encoded = RunLengthEncoder.encode(Arrays.asList(SAMPLE_PLAIN));
28 assertEquals(Arrays.asList(SAMPLE_ENCODED), encoded);
29 }
30
31 @Test
32 public void isSampleDecoded() {
33 List<Byte> decoded = RunLengthEncoder.decode(Arrays.asList(SAMPLE_ENCODED));
34 assertEquals(Arrays.asList(SAMPLE_PLAIN), decoded);
35 }
36
37 @Test
38 public void isSampleRunLengthListDecoded() {
39 List<RunLengthEncoder.RunLength> rll = RunLengthEncoder.decodeRunLengths(Arrays.asList(SAMPLE_ENCODED));
40 assertEquals(Arrays.asList(SAMPLE_RUN_LENGTHS), RunLengthEncoder.collapseRunLengths(rll));
41 }
42
43 @Test
44 public void isSampleRunLengthListCollapsed() {
45 final RunLengthEncoder.RunLength[] runLengths = {
46 new RunLengthEncoder.RunLength(1, (byte) 10),
47 new RunLengthEncoder.RunLength(2, (byte) 20),
48 new RunLengthEncoder.RunLength(3, (byte) 20)};
49 final RunLengthEncoder.RunLength[] expectedCollapsed = {
50 new RunLengthEncoder.RunLength(1, (byte) 10),
51 new RunLengthEncoder.RunLength(5, (byte) 20)};
52
53 List<RunLengthEncoder.RunLength> collapsed = RunLengthEncoder.collapseRunLengths(Arrays.asList(runLengths));
54 assertEquals(Arrays.asList(expectedCollapsed), collapsed);
55 }
56
57 @Test
58 public void isSampleRunLengthExpanded() {
59 final RunLengthEncoder.RunLength rl = new RunLengthEncoder.RunLength(5, (byte) 0);
60 final Byte[] expectedExpanded = {0, 0, 0, 0, 0};
61
62 assertEquals(Arrays.asList(expectedExpanded), rl.expand());
63 }
64
65 @Test
66 public void isSampleLongRunLengthSplit() {
67 final RunLengthEncoder.RunLength longRL = new RunLengthEncoder.RunLength(200, (byte) 0);
68 final RunLengthEncoder.RunLength[] expectedSplit = {
69 new RunLengthEncoder.RunLength(130, (byte) 0),
70 new RunLengthEncoder.RunLength(70, (byte) 0)};
71
72 assertEquals(Arrays.asList(expectedSplit), longRL.split());
73 }
74
75 @Test
76 public void isSampleRunLengthEncoded() {
77 final RunLengthEncoder.RunLength rl = new RunLengthEncoder.RunLength(5, (byte) 0);
78 final Byte[] expectedEncoded = {-3, 0};
79
80 assertEquals(Arrays.asList(expectedEncoded), rl.encode());
81 }
82
83 @Test
84 public void isSampleShortRunLengthEncoded() {
85 final RunLengthEncoder.RunLength rl = new RunLengthEncoder.RunLength(2, (byte) 0);
86 final Byte[] expectedEncoded = {0, 0};
87
88 assertEquals(Arrays.asList(expectedEncoded), rl.encode());
89 }
90
91 @Test
92 public void isSampleRunLengthDecoded() {
93 final Byte[] encoded = {-3, 0};
94 final RunLengthEncoder.RunLength expectedDecoded = new RunLengthEncoder.RunLength(5, (byte) 0);
95
96 RunLengthEncoder.RunLength decoded = new RunLengthEncoder.RunLength(encoded[0], encoded[1]);
97 assertEquals(expectedDecoded, decoded);
98 }
99
100}