]> git.saurik.com Git - redis.git/blobdiff - test-redis.tcl
Fixed issued #85 (getDecodedObject: Assertion 1 != 1 failed. While sorting a set...
[redis.git] / test-redis.tcl
index 354016e03bbc2f1875e2a8ef57b914f559ec996e..bf89d823bde4df72f5281ef6bf4c079d49bfb625 100644 (file)
@@ -1014,6 +1014,90 @@ proc main {server port} {
         list $v1 $v2 [$r zscore zset foo] [$r zscore zset bar]
     } {{bar foo} {foo bar} -2 6}
 
+    test {ZRANGEBYSCORE basics} {
+        $r del zset
+        $r zadd zset 1 a
+        $r zadd zset 2 b
+        $r zadd zset 3 c
+        $r zadd zset 4 d
+        $r zadd zset 5 e
+        $r zrangebyscore zset 2 4
+    } {b c d}
+
+    test {ZRANGEBYSCORE fuzzy test, 100 ranges in 1000 elements sorted set} {
+        set err {}
+        $r del zset
+        for {set i 0} {$i < 1000} {incr i} {
+            $r zadd zset [expr rand()] $i
+        }
+        for {set i 0} {$i < 100} {incr i} {
+            set min [expr rand()]
+            set max [expr rand()]
+            if {$min > $max} {
+                set aux $min
+                set min $max
+                set max $aux
+            }
+            set low [$r zrangebyscore zset -inf $min]
+            set ok [$r zrangebyscore zset $min $max]
+            set high [$r zrangebyscore zset $max +inf]
+            foreach x $low {
+                set score [$r zscore zset $x]
+                if {$score > $min} {
+                    append err "Error, score for $x is $score > $min\n"
+                }
+            }
+            foreach x $ok {
+                set score [$r zscore zset $x]
+                if {$score < $min || $score > $max} {
+                    append err "Error, score for $x is $score outside $min-$max range\n"
+                }
+            }
+            foreach x $high {
+                set score [$r zscore zset $x]
+                if {$score < $max} {
+                    append err "Error, score for $x is $score < $max\n"
+                }
+            }
+        }
+        set _ $err
+    } {}
+
+    test {ZRANGEBYSCORE with LIMIT} {
+        $r del zset
+        $r zadd zset 1 a
+        $r zadd zset 2 b
+        $r zadd zset 3 c
+        $r zadd zset 4 d
+        $r zadd zset 5 e
+        list \
+            [$r zrangebyscore zset 0 10 LIMIT 0 2] \
+            [$r zrangebyscore zset 0 10 LIMIT 2 3] \
+            [$r zrangebyscore zset 0 10 LIMIT 2 10] \
+            [$r zrangebyscore zset 0 10 LIMIT 20 10]
+    } {{a b} {c d e} {c d e} {}}
+
+    test {SORT against sorted sets} {
+        $r del zset
+        $r zadd zset 1 a
+        $r zadd zset 5 b
+        $r zadd zset 2 c
+        $r zadd zset 10 d
+        $r zadd zset 3 e
+        $r sort zset alpha desc
+    } {e d c b a}
+
+    test {Sorted sets +inf and -inf handling} {
+        $r del zset
+        $r zadd zset -100 a
+        $r zadd zset 200 b
+        $r zadd zset -300 c
+        $r zadd zset 1000000 d
+        $r zadd zset +inf max
+        $r zadd zset -inf min
+        $r zrange zset 0 -1
+    } {min c a b d max}
+
     test {EXPIRE - don't set timeouts multiple times} {
         $r set x foobar
         set v1 [$r expire x 5]