tiny fixes

This commit is contained in:
finley
2022-08-20 22:28:06 +08:00
parent 23a6f95c18
commit 9da335811f
8 changed files with 60 additions and 11 deletions

View File

@@ -2,18 +2,34 @@ package dict
import (
"github.com/hdt3213/godis/lib/utils"
"sort"
"testing"
)
func TestSimpleDict_Keys(t *testing.T) {
d := MakeSimple()
size := 10
var expectKeys []string
for i := 0; i < size; i++ {
d.Put(utils.RandString(5), utils.RandString(5))
str := utils.RandString(5)
d.Put(str, str)
expectKeys = append(expectKeys, str)
}
if len(d.Keys()) != size {
sort.Slice(expectKeys, func(i, j int) bool {
return expectKeys[i] > expectKeys[j]
})
keys := d.Keys()
if len(keys) != size {
t.Errorf("expect %d keys, actual: %d", size, len(d.Keys()))
}
sort.Slice(keys, func(i, j int) bool {
return keys[i] > keys[j]
})
for i, k := range keys {
if k != expectKeys[i] {
t.Errorf("expect %s actual %s", expectKeys[i], k)
}
}
}
func TestSimpleDict_PutIfExists(t *testing.T) {