|
13 | 13 | import dev.zarr.zarrjava.utils.MultiArrayUtils;
|
14 | 14 | import dev.zarr.zarrjava.v3.*;
|
15 | 15 | import dev.zarr.zarrjava.v3.codec.CodecBuilder;
|
| 16 | +import dev.zarr.zarrjava.v3.codec.core.BytesCodec; |
16 | 17 | import dev.zarr.zarrjava.v3.codec.core.TransposeCodec;
|
17 | 18 | import org.junit.jupiter.api.Assertions;
|
18 | 19 | import org.junit.jupiter.api.BeforeAll;
|
|
32 | 33 | import java.util.Comparator;
|
33 | 34 | import java.util.HashMap;
|
34 | 35 | import java.util.Map;
|
| 36 | +import java.util.function.Function; |
35 | 37 | import java.util.stream.Stream;
|
36 | 38 |
|
37 | 39 | import static org.junit.Assert.assertThrows;
|
@@ -231,17 +233,39 @@ public void testWriteReadWithZarrita(String codec, String codecParam) throws Exc
|
231 | 233 | assert exitCode == 0;
|
232 | 234 | }
|
233 | 235 |
|
234 |
| - static Stream<int[]> invalidchunkSizes() { |
| 236 | + static Stream<Function<CodecBuilder, CodecBuilder>> invalidCodecBuilder(){ |
235 | 237 | return Stream.of(
|
236 |
| - new int[] {1} , |
237 |
| - new int[] {1, 1, 1}, |
| 238 | + c -> c.withBytes(BytesCodec.Endian.LITTLE).withBytes(BytesCodec.Endian.LITTLE), |
| 239 | + c -> c.withBlosc().withBytes(BytesCodec.Endian.LITTLE), |
| 240 | + c -> c.withBytes(BytesCodec.Endian.LITTLE).withTranspose(new int[]{1,0}), |
| 241 | + c -> c.withTranspose(new int[]{1,0}).withBytes(BytesCodec.Endian.LITTLE).withTranspose(new int[]{1,0}) |
| 242 | + ); |
| 243 | + } |
| 244 | + |
| 245 | + @ParameterizedTest |
| 246 | + @MethodSource("invalidCodecBuilder") |
| 247 | + public void testCheckInvalidCodecConfiguration(Function<CodecBuilder, CodecBuilder> codecBuilder) throws Exception { |
| 248 | + StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("invalid_codec_config", String.valueOf(codecBuilder.hashCode())); |
| 249 | + ArrayMetadataBuilder builder = Array.metadataBuilder() |
| 250 | + .withShape(new long[] {4, 4}) |
| 251 | + .withDataType(DataType.UINT32) |
| 252 | + .withChunkShape(new int[]{2,2}) |
| 253 | + .withCodecs(codecBuilder); |
| 254 | + |
| 255 | + assertThrows(ZarrException.class, () -> Array.create(storeHandle, builder.build())); |
| 256 | + } |
| 257 | + |
| 258 | + static Stream<int[]> invalidChunkSizes() { |
| 259 | + return Stream.of( |
| 260 | + new int[]{1}, |
| 261 | + new int[]{1, 1, 1}, |
238 | 262 | new int[] {5, 1},
|
239 | 263 | new int[] {1, 5}
|
240 | 264 | );
|
241 | 265 | }
|
242 | 266 |
|
243 | 267 | @ParameterizedTest
|
244 |
| - @MethodSource("invalidchunkSizes") |
| 268 | + @MethodSource("invalidChunkSizes") |
245 | 269 | public void testCheckInvalidChunkBounds(int[] chunkSize) throws Exception {
|
246 | 270 | long[] shape = new long[] {4, 4};
|
247 | 271 |
|
@@ -310,31 +334,46 @@ public void testZstdCodecReadWrite(int clevel, boolean checksum) throws ZarrExce
|
310 | 334 | @Test
|
311 | 335 | public void testTransposeCodec() throws ZarrException {
|
312 | 336 | ucar.ma2.Array testData = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{2, 3, 3}, new int[]{
|
313 |
| - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}); |
| 337 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}); |
314 | 338 | ucar.ma2.Array testDataTransposed120 = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{3, 3, 2}, new int[]{
|
315 |
| - 0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7, 16, 8, 17}); |
| 339 | + 0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7, 16, 8, 17}); |
316 | 340 |
|
317 |
| - ArrayMetadata.CoreArrayMetadata metadata = new ArrayMetadata.CoreArrayMetadata( |
318 |
| - new long[]{2, 3, 3}, |
319 |
| - new int[]{2, 3, 3}, |
320 |
| - DataType.UINT32, |
321 |
| - null); |
322 | 341 | TransposeCodec transposeCodec = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 0}));
|
323 |
| - TransposeCodec transposeCodecWrongOrder1 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 2})); |
324 |
| - TransposeCodec transposeCodecWrongOrder2 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 3})); |
325 |
| - TransposeCodec transposeCodecWrongOrder3 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 3, 0})); |
326 |
| - transposeCodec.setCoreArrayMetadata(metadata); |
327 |
| - transposeCodecWrongOrder1.setCoreArrayMetadata(metadata); |
328 |
| - transposeCodecWrongOrder2.setCoreArrayMetadata(metadata); |
329 |
| - transposeCodecWrongOrder3.setCoreArrayMetadata(metadata); |
| 342 | + transposeCodec.setCoreArrayMetadata(new ArrayMetadata.CoreArrayMetadata( |
| 343 | + new long[]{2, 3, 3}, |
| 344 | + new int[]{2, 3, 3}, |
| 345 | + DataType.UINT32, |
| 346 | + null)); |
330 | 347 |
|
331 | 348 | assert MAMath.equals(testDataTransposed120, transposeCodec.encode(testData));
|
332 | 349 | assert MAMath.equals(testData, transposeCodec.decode(testDataTransposed120));
|
333 |
| - assertThrows(ZarrException.class, () -> transposeCodecWrongOrder1.encode(testData)); |
334 |
| - assertThrows(ZarrException.class, () -> transposeCodecWrongOrder2.encode(testData)); |
335 |
| - assertThrows(ZarrException.class, () -> transposeCodecWrongOrder3.encode(testData)); |
336 | 350 | }
|
337 | 351 |
|
| 352 | + static Stream<int[]> invalidTransposeOrder() { |
| 353 | + return Stream.of( |
| 354 | + new int[]{1, 0, 0}, |
| 355 | + new int[]{1, 2, 3}, |
| 356 | + new int[]{1,2,3,0}, |
| 357 | + new int[]{1,2} |
| 358 | + ); |
| 359 | + } |
| 360 | + |
| 361 | + @ParameterizedTest |
| 362 | + @MethodSource("invalidChunkSizes") |
| 363 | + public void testCheckInvalidTransposeOrder(int[] transposeOrder) throws Exception { |
| 364 | + int[] shapeInt = new int[]{2, 3, 3}; |
| 365 | + long[] shapeLong = new long[]{2, 3, 3}; |
| 366 | + |
| 367 | + TransposeCodec transposeCodec = new TransposeCodec(new TransposeCodec.Configuration(transposeOrder)); |
| 368 | + transposeCodec.setCoreArrayMetadata(new ArrayMetadata.CoreArrayMetadata( |
| 369 | + shapeLong, |
| 370 | + shapeInt, |
| 371 | + DataType.UINT32, |
| 372 | + null)); |
| 373 | + |
| 374 | + ucar.ma2.Array testData = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, shapeInt); |
| 375 | + assertThrows(ZarrException.class, () -> transposeCodec.encode(testData)); |
| 376 | + } |
338 | 377 | @Test
|
339 | 378 | public void testFileSystemStores() throws IOException, ZarrException {
|
340 | 379 | FilesystemStore fsStore = new FilesystemStore(TESTDATA);
|
|
0 commit comments