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

Function TestSet_SUnion

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

Source from the content-addressed store, hash-verified

399}
400
401func TestSet_SUnion(t *testing.T) {
402 set := NewSet()
403
404 key1 := "set1"
405 key2 := "set2"
406 key3 := "set3"
407 key4 := "set4"
408
409 expectRecords := testutils.GenerateRecords(10)
410
411 values := make([][]byte, 10)
412 for i := range expectRecords {
413 values[i] = expectRecords[i].Value
414 }
415
416 require.NoError(t, set.SAdd(key1, values[:5], expectRecords[:5]))
417 require.NoError(t, set.SAdd(key2, values[2:6], expectRecords[2:6]))
418 require.NoError(t, set.SAdd(key3, values[2:7], expectRecords[2:7]))
419 require.NoError(t, set.SAdd(key4, values[7:], expectRecords[7:]))
420
421 type args struct {
422 key1 string
423 key2 string
424 }
425
426 tests := []struct {
427 name string
428 args args
429 set *Set
430 want []*core.Record
431 wantErr bool
432 }{
433 {"normal set Union1", args{key1, key4}, set,
434 []*core.Record{expectRecords[0], expectRecords[1], expectRecords[2], expectRecords[3], expectRecords[4], expectRecords[7], expectRecords[8], expectRecords[9]},
435 false},
436 {
437 "normal set Union2", args{key2, key3}, set,
438 []*core.Record{expectRecords[2], expectRecords[3], expectRecords[4], expectRecords[5], expectRecords[6]},
439 false,
440 },
441 {"first fake set", args{"fake_key1", key2}, set, nil, true},
442 {"second fake set", args{key1, "fake_key2"}, set, nil, true},
443 {"two fake set", args{"fake_key1", "fake_key2"}, set, nil, true},
444 }
445
446 for _, tt := range tests {
447 t.Run(tt.name, func(t *testing.T) {
448 got, err := tt.set.SUnion(tt.args.key1, tt.args.key2)
449 if (err != nil) != tt.wantErr {
450 require.Errorf(t, err, "Get() error = %v, wantErr %v", tt.wantErr)
451 }
452 require.ElementsMatchf(t, tt.want, got, "Get() got = %v, want %v", got, tt.want)
453 })
454 }
455}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected