Skip to content

Commit db122db

Browse files
committed
add testCodecTranspose
1 parent 0f50859 commit db122db

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

src/main/java/dev/zarr/zarrjava/v3/codec/core/TransposeCodec.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public long computeEncodedSize(long inputByteLength,
5454

5555
public static final class Configuration {
5656

57+
// TODO: order 'C' and 'F' are deprecated
58+
// https://zarr-specs.readthedocs.io/en/latest/v3/codecs/transpose/v1.0.html#transpose-codec-v1
5759
public final String order;
5860

5961
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)

src/test/java/dev/zarr/zarrjava/ZarrTest.java

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
import dev.zarr.zarrjava.store.StoreHandle;
1111
import dev.zarr.zarrjava.utils.MultiArrayUtils;
1212
import dev.zarr.zarrjava.v3.*;
13-
import org.junit.jupiter.api.Assertions;
14-
import org.junit.jupiter.api.BeforeAll;
15-
import org.junit.jupiter.api.Disabled;
16-
import org.junit.jupiter.api.Test;
13+
import dev.zarr.zarrjava.v3.codec.core.TransposeCodec;
14+
import org.junit.jupiter.api.*;
1715
import org.junit.jupiter.params.ParameterizedTest;
1816
import org.junit.jupiter.params.provider.ValueSource;
1917

@@ -36,12 +34,12 @@ public class ZarrTest {
3634

3735
final static Path TESTDATA = Paths.get("testdata");
3836
final static Path TESTOUTPUT = Paths.get("testoutput");
39-
4037
//TODO: is the Path with / instead of \ readable in Windows?
4138
final static Path ZARRITA_WRITE_PATH = Paths.get("src/test/java/dev/zarr/zarrjava/zarrita_write.py");
4239
final static Path ZARRITA_READ_PATH = Paths.get("src/test/java/dev/zarr/zarrjava/zarrita_read.py");
43-
4440
final static String CONDA_ENVIRONMENT = "zarrita_env";
41+
static ucar.ma2.Array testData;
42+
static ucar.ma2.Array testDataTransposed;
4543

4644
@BeforeAll
4745
public static void clearTestoutputFolder() throws IOException {
@@ -96,6 +94,52 @@ public static void installZarritaInCondaEnv() throws IOException {
9694
}
9795
}
9896

97+
@BeforeEach
98+
public void fillTestData() {
99+
testData = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{4, 4, 4}, new int[]{
100+
0, 1, 2, 3,
101+
4, 5, 6, 7,
102+
8, 9, 10, 11,
103+
12, 13, 14, 15,
104+
105+
16, 17, 18, 19,
106+
20, 21, 22, 23,
107+
24, 25, 26, 27,
108+
28, 29, 30, 31,
109+
110+
32, 33, 34, 35,
111+
36, 37, 38, 39,
112+
40, 41, 42, 43,
113+
44, 45, 46, 47,
114+
115+
48, 49, 50, 51,
116+
52, 53, 54, 55,
117+
56, 57, 58, 59,
118+
60, 61, 62, 63
119+
});
120+
testDataTransposed = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{4, 4, 4}, new int[]{
121+
0, 16, 32, 48,
122+
4, 20, 36, 52,
123+
8, 24, 40, 56,
124+
12, 28, 44, 60,
125+
126+
1, 17, 33, 49,
127+
5, 21, 37, 53,
128+
9, 25, 41, 57,
129+
13, 29, 45, 61,
130+
131+
2, 18, 34, 50,
132+
6, 22, 38, 54,
133+
10, 26, 42, 58,
134+
14, 30, 46, 62,
135+
136+
3, 19, 35, 51,
137+
7, 23, 39, 55,
138+
11, 27, 43, 59,
139+
15, 31, 47, 63
140+
});
141+
}
142+
99143
@ParameterizedTest
100144
@ValueSource(strings = {"blosc", "gzip", "zstd", "bytes", "transpose", "sharding", "crc32c"})
101145
public void testReadFromZarrita(String codec) throws IOException, ZarrException, InterruptedException {
@@ -251,6 +295,21 @@ public void testCodecsWriteRead(String codec) throws IOException, ZarrException,
251295
Assertions.assertArrayEquals(testData, (int[]) result.get1DJavaArray(ucar.ma2.DataType.INT));
252296
}
253297

298+
@ParameterizedTest
299+
@ValueSource(strings = {"F", "C"})
300+
public void testCodecTranspose(String order) throws IOException, ZarrException, InterruptedException {
301+
ArrayMetadata.CoreArrayMetadata metadata = new ArrayMetadata.CoreArrayMetadata(
302+
new long[]{4, 4, 4},
303+
new int[]{4, 4, 4},
304+
DataType.UINT32,
305+
null);
306+
TransposeCodec transposeCodec = new TransposeCodec(new TransposeCodec.Configuration(order));
307+
308+
//TODO is that what is expected?
309+
assertEquals(testDataTransposed, transposeCodec.encode(testData, metadata));
310+
assertEquals(testData, transposeCodec.decode(testDataTransposed, metadata));
311+
}
312+
254313
@Test
255314
public void testFileSystemStores() throws IOException, ZarrException {
256315
FilesystemStore fsStore = new FilesystemStore(TESTDATA);

0 commit comments

Comments
 (0)