github.com/parquet-go/parquet-go@v0.21.1-0.20240501160520-b3c3a0c3ed6f/internal/unsafecast/unsafecast_test.go (about) 1 package unsafecast_test 2 3 import ( 4 "testing" 5 6 "github.com/parquet-go/parquet-go/internal/unsafecast" 7 ) 8 9 func TestUnsafeCastSlice(t *testing.T) { 10 a := make([]uint32, 4, 13) 11 a[0] = 1 12 a[1] = 0 13 a[2] = 2 14 a[3] = 0 15 16 b := unsafecast.Slice[int64](a) 17 if len(b) != 2 { // (4 * sizeof(uint32)) / sizeof(int64) 18 t.Fatalf("length mismatch: want=2 got=%d", len(b)) 19 } 20 if cap(b) != 6 { // (13 * sizeof(uint32)) / sizeof(int64) 21 t.Fatalf("capacity mismatch: want=7 got=%d", cap(b)) 22 } 23 if b[0] != 1 { 24 t.Errorf("wrong value at index 0: want=1 got=%d", b[0]) 25 } 26 if b[1] != 2 { 27 t.Errorf("wrong value at index 1: want=2 got=%d", b[1]) 28 } 29 30 c := unsafecast.Slice[uint32](b) 31 if len(c) != 4 { 32 t.Fatalf("length mismatch: want=2 got=%d", len(b)) 33 } 34 if cap(c) != 12 { 35 t.Fatalf("capacity mismatch: want=7 got=%d", cap(b)) 36 } 37 for i := range c { 38 if c[i] != a[i] { 39 t.Errorf("wrong value at index %d: want=%d got=%d", i, a[i], c[i]) 40 } 41 } 42 }