forked from sbinet/go-hdf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h5s_test.go
101 lines (84 loc) · 2.24 KB
/
h5s_test.go
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package hdf5
import (
"testing"
)
func TestDataspace(t *testing.T) {
// Creating this dataspace results in an error.
if _, err := CreateDataspace(S_NO_CLASS); err == nil {
t.Errorf("expected an error, but got nil")
}
// These dataspaces are legitimate.
classes := []SpaceClass{S_SCALAR, S_SIMPLE, S_NULL}
for _, class := range classes {
// Create a new Dataspace
ds, err := CreateDataspace(class)
if err != nil {
t.Fatal(err)
}
if ds.SimpleExtentType() != class {
t.Errorf("Dataspace class mismatch: %q != %q", ds.SimpleExtentType(), class)
}
// Copy the Dataspace
clone, err := ds.Copy()
if err != nil {
t.Fatal(err)
}
if ds.Name() != clone.Name() {
t.Errorf("original dataspace name %q != clone name %q", ds.Name(), clone.Name())
}
if ds.IsSimple() != clone.IsSimple() {
t.Errorf("original dataspace simplicity %v != clone simplicity: %v", ds.IsSimple(), clone.IsSimple())
}
// Close the Dataspace
if err = ds.Close(); err != nil {
t.Fatal(err)
}
}
}
func TestSimpleDataspace(t *testing.T) {
dims := []uint{3, 3, 3}
maxdims := []uint{9, 9, 9}
ds, err := CreateSimpleDataspace(dims, maxdims)
if err != nil {
t.Fatal(err)
}
dsDims, dsMaxdims, err := ds.SimpleExtentDims()
if err != nil {
t.Fatal(err)
}
if !arrayEq(dims, dsDims) {
t.Errorf("retrieved dims not equal: %v != %v", dims, dsDims)
}
if !arrayEq(maxdims, dsMaxdims) {
t.Errorf("retrieved maxdims not equal: %v != %v", maxdims, dsMaxdims)
}
if ds.SimpleExtentNDims() != 3 {
t.Errorf("wrong number of dimensions: got %d, want %d", ds.SimpleExtentNDims(), 3)
}
if ds.SimpleExtentType() != S_SIMPLE {
t.Errorf("wrong extent type: got %d, want %d", ds.SimpleExtentType(), S_SIMPLE)
}
// npoints should be 3 * 3 * 3
npoints := ds.SimpleExtentNPoints()
if npoints != 27 {
t.Errorf("wrong number of npoints: got %d, want %d", npoints, 27)
}
// SetOffset should only work for array a where len(a) == len(dims)
if err = ds.SetOffset([]uint{1, 1, 1}); err != nil {
t.Fatal(err)
}
if err = ds.SetOffset([]uint{1}); err == nil {
t.Error("expected a non-nil error")
}
}
func arrayEq(a, b []uint) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}