-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathTestUtils.java
More file actions
80 lines (68 loc) · 3.09 KB
/
TestUtils.java
File metadata and controls
80 lines (68 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package dev.zarr.zarrjava;
import dev.zarr.zarrjava.utils.IndexingUtils;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import java.util.Arrays;
import static dev.zarr.zarrjava.utils.IndexingUtils.computeChunkCoords;
import static dev.zarr.zarrjava.utils.Utils.inversePermutation;
import static dev.zarr.zarrjava.utils.Utils.isPermutation;
public class TestUtils {
@Test
public void testIsPermutation() {
assert isPermutation(new int[]{2, 1, 0});
assert isPermutation(new int[]{4, 2, 1, 3, 0});
assert !isPermutation(new int[]{0, 1, 2, 0});
assert !isPermutation(new int[]{0, 1, 2, 3, 5});
assert !isPermutation(new int[]{});
}
@Test
public void testInversePermutation() {
Assertions.assertArrayEquals(new int[]{1, 0, 2}, inversePermutation(new int[]{1, 0, 2}));
Assertions.assertArrayEquals(new int[]{2, 0, 1}, inversePermutation(new int[]{1, 2, 0}));
Assertions.assertArrayEquals(new int[]{0, 3, 2, 4, 1}, inversePermutation(new int[]{0, 4, 2, 1, 3}));
Assertions.assertFalse(Arrays.equals(new int[]{2, 0, 1}, inversePermutation(new int[]{2, 0, 1})));
}
@Test
public void testComputeChunkCoords(){
long[] arrayShape = new long[]{100, 100};
int[] chunkShape = new int[]{30, 30};
long[] selOffset = new long[]{50, 20};
int[] selShape = new int[]{20, 1};
long[][] chunkCoords = computeChunkCoords(arrayShape, chunkShape, selOffset, selShape);
long[][] expectedChunkCoords = new long[][]{
{1, 0},
{2, 0},
};
Assertions.assertArrayEquals(expectedChunkCoords, chunkCoords);
arrayShape = new long[]{1, 52};
chunkShape = new int[]{1, 17};
selOffset = new long[]{0, 32};
selShape = new int[]{1, 20};
chunkCoords = computeChunkCoords(arrayShape, chunkShape, selOffset, selShape);
expectedChunkCoords = new long[][]{
{0, 1},
{0, 2},
{0, 3},
};
Assertions.assertArrayEquals(expectedChunkCoords, chunkCoords);
}
@Test
public void testComputeProjection(){
// chunk (0,2) contains indexes 34-50 along axis 1
// thus the overlap with selection 32-52 is 34-50
// which is offset 2 in the selection and offset 0 in the chunk
// and has full chunk length 17
final long[] chunkCoords = new long[]{0, 2};
final long[] arrayShape = new long[]{1, 52};
final int[] chunkShape = new int[]{1, 17};
final long[] selOffset = new long[]{0, 32};
final int[] selShape = new int[]{1, 20};
IndexingUtils.ChunkProjection projection = IndexingUtils.computeProjection(
chunkCoords, arrayShape, chunkShape, selOffset, selShape
);
Assertions.assertArrayEquals(chunkCoords, projection.chunkCoords);
Assertions.assertArrayEquals(new int[]{0,0}, projection.chunkOffset);
Assertions.assertArrayEquals(new int[]{0,2}, projection.outOffset);
Assertions.assertArrayEquals(new int[]{1, 17}, projection.shape);
}
}