Skip to content

Commit

Permalink
test(rdb): set test
Browse files Browse the repository at this point in the history
  • Loading branch information
vczyh committed Jan 26, 2024
1 parent 606e59a commit fa863b2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/rdb/types/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ func testOne(t *testing.T, typeByte byte, setData string, values []string) {
}
o := new(SetObject)
o.LoadFromBuffer(bytes.NewReader([]byte(setData[1:])), "key", typeByte)
if len(o.elements) != len(values) {
t.Errorf("elements not match. len(o.elements)=[%d], len(values)=[%d]", len(o.elements), len(values))
cmdC := o.Rewrite()
var elements []string
for cmd := range cmdC {
elements = append(elements, cmd[2])
}
count := len(o.elements)
sort.Strings(o.elements)
if len(elements) != len(values) {
t.Errorf("elements not match. len(o.elements)=[%d], len(values)=[%d]", len(elements), len(values))
}
count := len(elements)
sort.Strings(elements)
sort.Strings(values)
// check set
for i := 0; i < count; i++ {
if o.elements[i] != values[i] {
t.Errorf("elements not match. o.elements[i]=[%s], values[i]=[%s]", o.elements[i], values[i])
if elements[i] != values[i] {
t.Errorf("elements not match. o.elements[i]=[%s], values[i]=[%s]", elements[i], values[i])
}
}
}
Expand Down

0 comments on commit fa863b2

Please sign in to comment.