Skip to content

Commit

Permalink
Add test on filtered dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmudd committed Sep 29, 2024
1 parent 81962b6 commit 7f36255
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions jhdf/src/test/java/io/jhdf/dataset/ChunkedV4DatasetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
}

0 comments on commit 7f36255

Please sign in to comment.