From 7f36255fa969745f7801626f395ae806c1a10d0a Mon Sep 17 00:00:00 2001 From: James Mudd Date: Sun, 29 Sep 2024 14:49:47 +0100 Subject: [PATCH] Add test on filtered dataset --- .../io/jhdf/dataset/ChunkedV4DatasetTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/jhdf/src/test/java/io/jhdf/dataset/ChunkedV4DatasetTest.java b/jhdf/src/test/java/io/jhdf/dataset/ChunkedV4DatasetTest.java index 2c0ec59b..1bafd6cd 100644 --- a/jhdf/src/test/java/io/jhdf/dataset/ChunkedV4DatasetTest.java +++ b/jhdf/src/test/java/io/jhdf/dataset/ChunkedV4DatasetTest.java @@ -33,8 +33,10 @@ import static io.jhdf.Utils.flatten; import static org.apache.commons.lang3.ArrayUtils.toObject; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isA; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -131,4 +133,26 @@ void testGettingDecompressedChunkWithoutFiltersIsTheSameAsRaw() { rawChunkBuffer.get(rawChunkBytes); assertThat(rawChunkBytes, is(decompressedChunkBytes)); } + + @Test + void testGettingDecompressedChunkWithFilters() { + Dataset dataset = hdfFile.getDatasetByPath("/filtered_fixed_array/int32"); + assertThat(dataset, isA(ChunkedDataset.class)); + ChunkedDataset chunkedDataset = (ChunkedDataset) dataset; + assertThat(toObject(chunkedDataset.getChunkDimensions()), is(arrayContaining(2, 3))); + assertThat(chunkedDataset.getFilters(), hasSize(1)); + + // Check the compressed and decompressed chunks are different + ByteBuffer rawChunkBuffer = chunkedDataset.getRawChunkBuffer(new int[]{0, 0}); + byte[] decompressedChunkBytes = chunkedDataset.getDecompressedChunk(new int[]{0, 0}); + byte[] rawChunkBytes = new byte[rawChunkBuffer.capacity()]; + rawChunkBuffer.get(rawChunkBytes); + assertThat(rawChunkBytes, is(not(decompressedChunkBytes))); + + IntBuffer intBuffer = ByteBuffer.wrap(decompressedChunkBytes).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); + int[] chunkData = new int[intBuffer.capacity()]; + intBuffer.get(chunkData); + + assertThat(toObject(chunkData), is(arrayContaining(0, 1, 2, 3, 4, 5))); + } }