MCPcopy Index your code
hub / github.com/Workiva/go-datastructures / TestBitArraySerialization

Function TestBitArraySerialization

bitarray/encoding_test.go:49–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func TestBitArraySerialization(t *testing.T) {
50 numItems := uint64(1280)
51 input := newBitArray(numItems)
52
53 for i := uint64(0); i < numItems; i++ {
54 if i%3 == 0 {
55 input.SetBit(i)
56 }
57 }
58
59 outBytes, err := input.Serialize()
60 assert.Equal(t, err, nil)
61
62 // 1280 bits = 20 blocks = 160 bytes, plus lowest and highest at
63 // 128 bits = 16 bytes plus 1 byte for the anyset param and the identifer
64 assert.Equal(t, len(outBytes), 178)
65
66 expected := []byte{66, 0, 0, 0, 0, 0, 0, 0, 0, 254}
67 assert.Equal(t, expected, outBytes[:10])
68
69 output := newBitArray(0)
70 err = output.Deserialize(outBytes)
71 assert.Equal(t, err, nil)
72 assert.True(t, input.Equals(output))
73}
74
75func TestBitArrayMarshalUnmarshal(t *testing.T) {
76 numItems := uint64(1280)

Callers

nothing calls this directly

Calls 5

newBitArrayFunction · 0.85
SetBitMethod · 0.65
EqualsMethod · 0.65
SerializeMethod · 0.45
DeserializeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…