mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-06 01:07:06 +08:00
tiny fixes
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user