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

Function TestSet_SInter

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

Source from the content-addressed store, hash-verified

153}
154
155func TestSet_SInter(t *testing.T) {
156 set := NewSet()
157
158 key1 := "set1"
159 key2 := "set2"
160 key3 := "set3"
161 key4 := "set4"
162
163 expectRecords := testutils.GenerateRecords(10)
164
165 values := make([][]byte, 10)
166 for i := range expectRecords {
167 values[i] = expectRecords[i].Value
168 }
169
170 require.NoError(t, set.SAdd(key1, values[:5], expectRecords[:5]))
171 require.NoError(t, set.SAdd(key2, values[2:6], expectRecords[2:6]))
172 require.NoError(t, set.SAdd(key3, values[2:7], expectRecords[2:7]))
173 require.NoError(t, set.SAdd(key4, values[7:], expectRecords[7:]))
174
175 type args struct {
176 key1 string
177 key2 string
178 }
179
180 tests := []struct {
181 name string
182 args args
183 set *Set
184 want []*core.Record
185 wantErr bool
186 }{
187 {"normal set inter1", args{key1, key2}, set, []*core.Record{expectRecords[2], expectRecords[3], expectRecords[4]}, false},
188 {"normal set inter1", args{key2, key3}, set, []*core.Record{expectRecords[2], expectRecords[3], expectRecords[4], expectRecords[5]}, false},
189 {"normal set inter2", args{key1, key4}, set, nil, false},
190 {"first fake set", args{"fake_key1", key2}, set, nil, true},
191 {"second fake set", args{key1, "fake_key2"}, set, nil, true},
192 {"two fake set", args{"fake_key1", "fake_key2"}, set, nil, true},
193 }
194
195 for _, tt := range tests {
196 t.Run(tt.name, func(t *testing.T) {
197 got, err := tt.set.SInter(tt.args.key1, tt.args.key2)
198 if (err != nil) != tt.wantErr {
199 require.Errorf(t, err, "Get() error = %v, wantErr %v", tt.wantErr)
200 }
201 require.ElementsMatchf(t, tt.want, got, "Get() got = %v, want %v", got, tt.want)
202 })
203 }
204}
205
206func TestSet_SMembers(t *testing.T) {
207 set := NewSet()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected