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

Function TestGetSetBits

bitarray/bitarray_test.go:221–248  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

219}
220
221func TestGetSetBits(t *testing.T) {
222 ba := newBitArray(1000)
223 buf := make([]uint64, 0, 5)
224
225 require.NoError(t, ba.SetBit(1))
226 require.NoError(t, ba.SetBit(4))
227 require.NoError(t, ba.SetBit(8))
228 require.NoError(t, ba.SetBit(63))
229 require.NoError(t, ba.SetBit(64))
230 require.NoError(t, ba.SetBit(200))
231 require.NoError(t, ba.SetBit(1000))
232
233 assert.Equal(t, []uint64(nil), ba.GetSetBits(0, nil))
234 assert.Equal(t, []uint64{}, ba.GetSetBits(0, []uint64{}))
235
236 assert.Equal(t, []uint64{1, 4, 8, 63, 64}, ba.GetSetBits(0, buf))
237 assert.Equal(t, []uint64{63, 64, 200, 1000}, ba.GetSetBits(10, buf))
238 assert.Equal(t, []uint64{63, 64, 200, 1000}, ba.GetSetBits(63, buf))
239 assert.Equal(t, []uint64{200, 1000}, ba.GetSetBits(128, buf))
240
241 require.NoError(t, ba.ClearBit(4))
242 require.NoError(t, ba.ClearBit(64))
243 assert.Equal(t, []uint64{1, 8, 63, 200, 1000}, ba.GetSetBits(0, buf))
244 assert.Empty(t, ba.GetSetBits(1001, buf))
245
246 ba.Reset()
247 assert.Empty(t, ba.GetSetBits(0, buf))
248}
249
250func BenchmarkGetSetBits(b *testing.B) {
251 numItems := uint64(168000)

Callers

nothing calls this directly

Calls 6

newBitArrayFunction · 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…