-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patharray_test.go
More file actions
48 lines (44 loc) · 953 Bytes
/
Copy patharray_test.go
File metadata and controls
48 lines (44 loc) · 953 Bytes
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
package apl
import "testing"
func TestIdx(t *testing.T) {
testCases := []struct {
shape []int
idx []int
n int
}{
{[]int{2}, []int{1}, 1},
{[]int{2, 2, 4}, []int{1, 1, 3}, 15},
{[]int{3, 4, 2}, []int{1, 3, 0}, 14},
}
// Test IdxConverter
for _, tc := range testCases {
ic, idx := NewIdxConverter(tc.shape)
ic.Indexes(tc.n, idx)
for i := range idx {
if idx[i] != tc.idx[i] {
t.Fatalf("expected %v got %v", tc.idx, idx)
}
}
n := ic.Index(idx)
if n != tc.n {
t.Fatalf("expected %d got %d", tc.n, n)
}
}
// Test ArraySize and IncArrayIndex
for _, tc := range testCases {
ar := MixedArray{Dims: tc.shape}
ic, idx := NewIdxConverter(tc.shape)
for i := 0; i < ar.Size(); i++ {
n := ic.Index(idx)
if n != i {
t.Fatalf("expected %d got %d", i, n)
}
IncArrayIndex(idx, tc.shape)
}
for i := range idx {
if idx[i] != 0 {
t.Fatalf("idx should be zeros: %v", idx)
}
}
}
}