MCPcopy
hub / github.com/Workiva/go-datastructures / TestGetSetCompressedBits

Function TestGetSetCompressedBits

bitarray/sparse_bitarray_test.go:80–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestGetSetCompressedBits(t *testing.T) {
81 ba := newSparseBitArray()
82 buf := make([]uint64, 0, 5)
83
84 require.NoError(t, ba.SetBit(1))
85 require.NoError(t, ba.SetBit(4))
86 require.NoError(t, ba.SetBit(8))
87 require.NoError(t, ba.SetBit(63))
88 require.NoError(t, ba.SetBit(64))
89 require.NoError(t, ba.SetBit(200))
90 require.NoError(t, ba.SetBit(1000))
91
92 assert.Equal(t, []uint64(nil), ba.GetSetBits(0, nil))
93 assert.Equal(t, []uint64{}, ba.GetSetBits(0, []uint64{}))
94
95 assert.Equal(t, []uint64{1, 4, 8, 63, 64}, ba.GetSetBits(0, buf))
96 assert.Equal(t, []uint64{63, 64, 200, 1000}, ba.GetSetBits(10, buf))
97 assert.Equal(t, []uint64{63, 64, 200, 1000}, ba.GetSetBits(63, buf))
98 assert.Equal(t, []uint64{200, 1000}, ba.GetSetBits(128, buf))
99
100 require.NoError(t, ba.ClearBit(4))
101 require.NoError(t, ba.ClearBit(64))
102 assert.Equal(t, []uint64{1, 8, 63, 200, 1000}, ba.GetSetBits(0, buf))
103 assert.Empty(t, ba.GetSetBits(1001, buf))
104
105 ba.Reset()
106 assert.Empty(t, ba.GetSetBits(0, buf))
107}
108
109func BenchmarkGetSetCompressedBits(b *testing.B) {
110 ba := newSparseBitArray()

Callers

nothing calls this directly

Calls 6

newSparseBitArrayFunction · 0.85
SetBitMethod · 0.65
GetSetBitsMethod · 0.65
ClearBitMethod · 0.65
ResetMethod · 0.65
EmptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…