11package dev .zarr .zarrjava ;
22
33
4+ import dev .zarr .zarrjava .utils .IndexingUtils ;
45import org .junit .Test ;
56import org .junit .jupiter .api .Assertions ;
67
78import java .util .Arrays ;
89
10+ import static dev .zarr .zarrjava .utils .IndexingUtils .computeChunkCoords ;
911import static dev .zarr .zarrjava .utils .Utils .inversePermutation ;
1012import static dev .zarr .zarrjava .utils .Utils .isPermutation ;
1113
@@ -26,5 +28,53 @@ public void testInversePermutation() {
2628 Assertions .assertArrayEquals (new int []{0 , 3 , 2 , 4 , 1 }, inversePermutation (new int []{0 , 4 , 2 , 1 , 3 }));
2729 Assertions .assertFalse (Arrays .equals (new int []{2 , 0 , 1 }, inversePermutation (new int []{2 , 0 , 1 })));
2830 }
31+
32+ @ Test
33+ public void testComputeChunkCoords (){
34+ long [] arrayShape = new long []{100 , 100 };
35+ int [] chunkShape = new int []{30 , 30 };
36+ long [] selOffset = new long []{50 , 20 };
37+ int [] selShape = new int []{20 , 1 };
38+ long [][] chunkCoords = computeChunkCoords (arrayShape , chunkShape , selOffset , selShape );
39+ long [][] expectedChunkCoords = new long [][]{
40+ {1 , 0 },
41+ {2 , 0 },
42+ };
43+ Assertions .assertArrayEquals (expectedChunkCoords , chunkCoords );
44+
45+ arrayShape = new long []{1 , 52 };
46+ chunkShape = new int []{1 , 17 };
47+ selOffset = new long []{0 , 32 };
48+ selShape = new int []{1 , 20 };
49+ chunkCoords = computeChunkCoords (arrayShape , chunkShape , selOffset , selShape );
50+ expectedChunkCoords = new long [][]{
51+ {0 , 1 },
52+ {0 , 2 },
53+ {0 , 3 },
54+ };
55+ Assertions .assertArrayEquals (expectedChunkCoords , chunkCoords );
56+ }
57+
58+ @ Test
59+ public void testComputeProjection (){
60+ // chunk (0,2) contains indexes 34-50 along axis 1
61+ // thus the overlap with selection 32-52 is 34-50
62+ // which is offset 2 in the selection and offset 0 in the chunk
63+ // and has full chunk length 17
64+ final long [] chunkCoords = new long []{0 , 2 };
65+ final long [] arrayShape = new long []{1 , 52 };
66+ final int [] chunkShape = new int []{1 , 17 };
67+ final long [] selOffset = new long []{0 , 32 };
68+ final int [] selShape = new int []{1 , 20 };
69+
70+ IndexingUtils .ChunkProjection projection = IndexingUtils .computeProjection (
71+ chunkCoords , arrayShape , chunkShape , selOffset , selShape
72+ );
73+ Assertions .assertArrayEquals (chunkCoords , projection .chunkCoords );
74+ Assertions .assertArrayEquals (new int []{0 ,0 }, projection .chunkOffset );
75+ Assertions .assertArrayEquals (new int []{0 ,2 }, projection .outOffset );
76+ Assertions .assertArrayEquals (new int []{1 , 17 }, projection .shape );
77+ }
78+
2979}
3080
0 commit comments