add unit test

This commit is contained in:
wenyekui 2014-08-13 09:57:13 +08:00
parent 3927d2bd8f
commit e1a2ebc27a
2 changed files with 75 additions and 2 deletions

View File

@ -931,8 +931,7 @@ func (db *DB) ZUnionStore(destKey []byte, srcKeys [][]byte, weights []int64, agg
}
//todo add binlog
err := t.Commit()
if err != nil {
if err := t.Commit(); err != nil {
return 0, err
}
return int64(len(destMap)), nil
@ -995,5 +994,10 @@ func (db *DB) ZInterStore(destKey []byte, srcKeys [][]byte, weights []int64, agg
num++
}
}
//todo add binlog
if err := t.Commit(); err != nil {
return 0, err
}
return int64(len(keptMembers)), nil
}

View File

@ -296,4 +296,73 @@ func TestZUnionStore(t *testing.T) {
if v != 5 {
t.Fatal("invalid value ", v)
}
out = []byte("out")
n, err = db.ZUnionStore(out, keys, weights, AggregateMax)
if err != nil {
t.Fatal(err.Error())
}
if n != 3 {
t.Fatal("invalid value ", n)
}
v, err = db.ZScore(out, []byte("two"))
if err != nil {
t.Fatal(err.Error())
}
if v != 4 {
t.Fatal("invalid value ", v)
}
}
func TestZInterStore(t *testing.T) {
db := getTestDB()
key1 := []byte("key1")
key2 := []byte("key2")
db.ZAdd(key1, ScorePair{1, []byte("one")})
db.ZAdd(key1, ScorePair{1, []byte("two")})
db.ZAdd(key2, ScorePair{2, []byte("two")})
db.ZAdd(key2, ScorePair{2, []byte("three")})
keys := [][]byte{key1, key2}
weights := []int64{1, 2}
out := []byte("out")
n, err := db.ZInterStore(out, keys, weights, AggregateSum)
if err != nil {
t.Fatal(err.Error())
}
if n != 1 {
t.Fatal("invalid value ", n)
}
v, err := db.ZScore(out, []byte("two"))
if err != nil {
t.Fatal(err.Error())
}
if v != 5 {
t.Fatal("invalid value ", v)
}
out = []byte("out")
n, err = db.ZInterStore(out, keys, weights, AggregateMin)
if err != nil {
t.Fatal(err.Error())
}
if n != 1 {
t.Fatal("invalid value ", n)
}
v, err = db.ZScore(out, []byte("two"))
if err != nil {
t.Fatal(err.Error())
}
if v != 1 {
t.Fatal("invalid value ", v)
}
}