blob: 5a0e269b5d5bf4899870d4aaa5def83a0766ece4 [file] [log] [blame]
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package arrow_test
import (
"reflect"
"testing"
"github.com/apache/arrow/go/arrow"
)
{{- range .In}}
func Test{{.Name}}Traits(t *testing.T) {
const N = 10
b1 := arrow.{{.Name}}Traits.CastToBytes([]{{or .QualifiedType .Type}}{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
})
b2 := make([]byte, arrow.{{.Name}}Traits.BytesRequired(N))
for i := 0; i < N; i++ {
beg := i * arrow.{{.Name}}SizeBytes
end := (i + 1) * arrow.{{.Name}}SizeBytes
arrow.{{.Name}}Traits.PutValue(b2[beg:end], {{or .QualifiedType .Type}}(i))
}
if !reflect.DeepEqual(b1, b2) {
v1 := arrow.{{.Name}}Traits.CastFromBytes(b1)
v2 := arrow.{{.Name}}Traits.CastFromBytes(b2)
t.Fatalf("invalid values:\nb1=%v\nb2=%v\nv1=%v\nv2=%v\n", b1, b2, v1, v2)
}
v1 := arrow.{{.Name}}Traits.CastFromBytes(b1)
for i, v := range v1 {
if got, want := v, {{or .QualifiedType .Type}}(i); got != want {
t.Fatalf("invalid value[%d]. got=%v, want=%v", i, got, want)
}
}
v2 := make([]{{or .QualifiedType .Type}}, N)
arrow.{{.Name}}Traits.Copy(v2, v1)
if !reflect.DeepEqual(v1, v2) {
t.Fatalf("invalid values:\nv1=%v\nv2=%v\n", v1, v2)
}
}
{{end}}