Skip to content

Commit b320279

Browse files
author
Tara Drwenski
committed
Add unit test to test that shuffle gets applied to data that is not a multiple of the element size
1 parent 08d367c commit b320279

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cdm/core/src/test/java/ucar/nc2/filter/TestFilters.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import ucar.unidata.io.RandomAccessFile;
1212

1313
import java.io.IOException;
14+
import java.nio.ByteBuffer;
1415
import java.nio.charset.StandardCharsets;
1516
import java.util.HashMap;
1617
import java.util.Map;
@@ -59,6 +60,27 @@ public void testShuffle() throws IOException {
5960
testEncodeDecode(filter, "shuffle");
6061
}
6162

63+
@Test
64+
public void shouldShuffleDoublesAndLeaveIntAtEnd() throws IOException {
65+
ByteBuffer bb = ByteBuffer.allocate(2 * 8 + 4);
66+
bb.putDouble(-1.0);
67+
bb.putDouble(1.0);
68+
// to represent a checksum at the end of a chunk of doubles
69+
bb.putInt(12345);
70+
byte[] bytes = bb.array();
71+
72+
Map<String, Object> props = new HashMap<>();
73+
props.put("id", "shuffle");
74+
props.put("elementsize", 8);
75+
Filter filter = new Shuffle(props);
76+
77+
byte[] expected = new byte[] {-65, 63, -16, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 57};
78+
byte[] encoded = filter.encode(bytes);
79+
assertThat(encoded).isEqualTo(expected);
80+
byte[] decoded = filter.decode(encoded);
81+
assertThat(decoded).isEqualTo(bytes);
82+
}
83+
6284
@Test
6385
public void testChecksum32() throws IOException {
6486
// test Adler32

0 commit comments

Comments
 (0)