MCPcopy
hub / github.com/openacid/slim / TestI64EncodeDecode

Function TestI64EncodeDecode

array/int_test.go:1308–1387  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1306}
1307
1308func TestI64EncodeDecode(t *testing.T) {
1309
1310 indexes := []int32{1, 5, 9, 203}
1311 elts := []int64{12, 15, 19, 120}
1312
1313 cases := []struct {
1314 n int
1315 want []byte
1316 }{
1317 {
1318 0,
1319 []byte{},
1320 },
1321 {
1322 1,
1323 []byte{8, 1, 18, 1, 2, 26, 1, 0, 34},
1324 },
1325 {
1326 2,
1327 []byte{8, 2, 18, 1, 34, 26, 1, 0, 34},
1328 },
1329 }
1330
1331 for i, c := range cases {
1332
1333 a, err := array.NewI64(indexes[:c.n], elts[:c.n])
1334 if err != nil {
1335 t.Errorf("expect no error but: %s", err)
1336 }
1337
1338 rst, err := proto.Marshal(a)
1339 if err != nil {
1340 t.Errorf("expect no error but: %s", err)
1341 }
1342
1343 // build Elts part for template generated test codes
1344 var want []byte = c.want
1345 if c.n > 0 {
1346 want = append(c.want, byte(c.n*8))
1347 for i := 0; i < c.n; i++ {
1348 b := make([]byte, 8)
1349 binary.LittleEndian.PutUint64(b, uint64(elts[i]))
1350 want = append(want, b...)
1351 }
1352 }
1353
1354 if !reflect.DeepEqual(rst, want) {
1355 t.Fatalf("%d-th: n: %v; want: %v; actual: %v",
1356 i+1, c.n, want, rst)
1357 }
1358
1359 // Decode
1360
1361 b := &array.I64{}
1362 err = proto.Unmarshal(rst, b)
1363
1364 if err != nil {
1365 t.Errorf("expect no error but: %s", err)

Callers

nothing calls this directly

Calls 3

NewI64Function · 0.92
MarshalMethod · 0.80
UnmarshalMethod · 0.80

Tested by

no test coverage detected