MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / TestSet_SPop

Function TestSet_SPop

internal/data/set_test.go:295–336  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

293}
294
295func TestSet_SPop(t *testing.T) {
296 set := NewSet()
297
298 key := "set"
299
300 expectRecords := testutils.GenerateRecords(2)
301 values := make([][]byte, 2)
302 for i := range expectRecords {
303 values[i] = expectRecords[i].Value
304 }
305 m := map[*core.Record]struct{}{}
306 for _, expectRecord := range expectRecords {
307 m[expectRecord] = struct{}{}
308 }
309
310 require.NoError(t, set.SAdd(key, values, expectRecords))
311
312 tests := []struct {
313 name string
314 key string
315 set *Set
316 ok bool
317 }{
318 {"normal set SPop", key, set, true},
319 {"normal set SPop", key, set, true},
320 {"normal set SPop", key, set, false},
321 }
322
323 for _, tt := range tests {
324 t.Run(tt.name, func(t *testing.T) {
325 record := tt.set.SPop(tt.key)
326 _, ok := m[record]
327 require.Equal(t, tt.ok, ok)
328 })
329 }
330
331 t.Run("set SPop key not found", func(t *testing.T) {
332 s := NewSet()
333 rec := s.SPop("not_found_key")
334 assert.Nil(t, rec)
335 })
336}
337
338func TestSet_SIsMember(t *testing.T) {
339 set := NewSet()

Callers

nothing calls this directly

Calls 5

SAddMethod · 0.95
SPopMethod · 0.95
GenerateRecordsFunction · 0.92
NewSetFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected