Skip to content

Commit 842ad54

Browse files
committed
start remove constants "C" adn "F" from Transpose Codec's order
1 parent db122db commit 842ad54

File tree

2 files changed

+26
-67
lines changed

2 files changed

+26
-67
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,10 @@ public static final class Configuration {
5656

5757
// TODO: order 'C' and 'F' are deprecated
5858
// https://zarr-specs.readthedocs.io/en/latest/v3/codecs/transpose/v1.0.html#transpose-codec-v1
59-
public final String order;
59+
public final int[] order;
6060

6161
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
62-
public Configuration(@JsonProperty(value = "order", defaultValue = "C") String order)
63-
throws ZarrException {
64-
if (!order.equals("C") && !order.equals("F")) {
65-
throw new ZarrException("Only 'C' or 'F' are supported.");
66-
}
62+
public Configuration(@JsonProperty(value = "order") int[] order){
6763
this.order = order;
6864
}
6965
}

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

Lines changed: 24 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import dev.zarr.zarrjava.utils.MultiArrayUtils;
1212
import dev.zarr.zarrjava.v3.*;
1313
import dev.zarr.zarrjava.v3.codec.core.TransposeCodec;
14-
import org.junit.jupiter.api.*;
14+
import org.junit.jupiter.api.Assertions;
15+
import org.junit.jupiter.api.BeforeAll;
16+
import org.junit.jupiter.api.Disabled;
17+
import org.junit.jupiter.api.Test;
1518
import org.junit.jupiter.params.ParameterizedTest;
1619
import org.junit.jupiter.params.provider.ValueSource;
1720

@@ -27,8 +30,7 @@
2730
import java.util.Map;
2831
import java.util.stream.Stream;
2932

30-
import static org.junit.Assert.assertArrayEquals;
31-
import static org.junit.Assert.assertEquals;
33+
import static org.junit.Assert.*;
3234

3335
public class ZarrTest {
3436

@@ -38,8 +40,6 @@ public class ZarrTest {
3840
final static Path ZARRITA_WRITE_PATH = Paths.get("src/test/java/dev/zarr/zarrjava/zarrita_write.py");
3941
final static Path ZARRITA_READ_PATH = Paths.get("src/test/java/dev/zarr/zarrjava/zarrita_read.py");
4042
final static String CONDA_ENVIRONMENT = "zarrita_env";
41-
static ucar.ma2.Array testData;
42-
static ucar.ma2.Array testDataTransposed;
4343

4444
@BeforeAll
4545
public static void clearTestoutputFolder() throws IOException {
@@ -94,52 +94,6 @@ public static void installZarritaInCondaEnv() throws IOException {
9494
}
9595
}
9696

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-
14397
@ParameterizedTest
14498
@ValueSource(strings = {"blosc", "gzip", "zstd", "bytes", "transpose", "sharding", "crc32c"})
14599
public void testReadFromZarrita(String codec) throws IOException, ZarrException, InterruptedException {
@@ -295,19 +249,28 @@ public void testCodecsWriteRead(String codec) throws IOException, ZarrException,
295249
Assertions.assertArrayEquals(testData, (int[]) result.get1DJavaArray(ucar.ma2.DataType.INT));
296250
}
297251

298-
@ParameterizedTest
299-
@ValueSource(strings = {"F", "C"})
300-
public void testCodecTranspose(String order) throws IOException, ZarrException, InterruptedException {
252+
@Test
253+
public void testCodecTranspose() throws IOException, ZarrException, InterruptedException {
254+
ucar.ma2.Array testData = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{2, 3, 3}, new int[]{
255+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17});
256+
ucar.ma2.Array testDataTransposed120 = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{2, 3, 3}, new int[]{
257+
0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7, 16, 8, 17});
258+
301259
ArrayMetadata.CoreArrayMetadata metadata = new ArrayMetadata.CoreArrayMetadata(
302-
new long[]{4, 4, 4},
303-
new int[]{4, 4, 4},
260+
new long[]{2, 3, 3},
261+
new int[]{2, 3, 3},
304262
DataType.UINT32,
305263
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));
264+
TransposeCodec transposeCodec = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 0}));
265+
TransposeCodec transposeCodecWrongOrder1 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 2}));
266+
TransposeCodec transposeCodecWrongOrder2 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 3}));
267+
TransposeCodec transposeCodecWrongOrder3 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 3, 0}));
268+
269+
assertEquals(testDataTransposed120, transposeCodec.encode(testData, metadata));
270+
assertEquals(testData, transposeCodec.decode(testDataTransposed120, metadata));
271+
assertThrows(ZarrException.class, () -> transposeCodecWrongOrder1.encode(testData, metadata));
272+
assertThrows(ZarrException.class, () -> transposeCodecWrongOrder2.encode(testData, metadata));
273+
assertThrows(ZarrException.class, () -> transposeCodecWrongOrder3.encode(testData, metadata));
311274
}
312275

313276
@Test

0 commit comments

Comments
 (0)