From 396030a06f11b91212b898fb4a0fa8140b05c4a4 Mon Sep 17 00:00:00 2001 From: wenyekui Date: Wed, 13 Aug 2014 14:23:27 +0800 Subject: [PATCH] add unit test --- server/cmd_zset_test.go | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/server/cmd_zset_test.go b/server/cmd_zset_test.go index 06cd538..e6a6a70 100644 --- a/server/cmd_zset_test.go +++ b/server/cmd_zset_test.go @@ -643,4 +643,65 @@ func TestZUnionStore(t *testing.T) { t.Fatal("invalid value ", n) } } + + if n, err := ledis.Int64(c.Do("zscore", "out", "two")); err != nil { + t.Fatal(err.Error()) + } else { + if n != 2 { + t.Fatal("invalid value ", n) + } + } +} + +func TestZInterStore(t *testing.T) { + c := getTestConn() + defer c.Close() + + if _, err := c.Do("zadd", "k1", "1", "one"); err != nil { + t.Fatal(err.Error()) + } + + if _, err := c.Do("zadd", "k1", "2", "two"); err != nil { + t.Fatal(err.Error()) + } + + if _, err := c.Do("zadd", "k2", "1", "two"); err != nil { + t.Fatal(err.Error()) + } + + if _, err := c.Do("zadd", "k2", "2", "three"); err != nil { + t.Fatal(err.Error()) + } + + if n, err := ledis.Int64(c.Do("zinterstore", "out", "2", "k1", "k2", "weights", "1", "2")); err != nil { + t.Fatal(err.Error()) + } else { + if n != 1 { + t.Fatal("invalid value ", n) + } + } + + if n, err := ledis.Int64(c.Do("zinterstore", "out", "2", "k1", "k2", "aggregate", "min", "weights", "1", "2")); err != nil { + t.Fatal(err.Error()) + } else { + if n != 1 { + t.Fatal("invalid value ", n) + } + } + + if n, err := ledis.Int64(c.Do("zinterstore", "out", "2", "k1", "k2", "aggregate", "sum")); err != nil { + t.Fatal(err.Error()) + } else { + if n != 1 { + t.Fatal("invalid value ", n) + } + } + + if n, err := ledis.Int64(c.Do("zscore", "out", "two")); err != nil { + t.Fatal(err.Error()) + } else { + if n != 3 { + t.Fatal("invalid value ", n) + } + } }