]> git.saurik.com Git - redis.git/commitdiff
ZRANGEBYSCORE fuzzy test
authorantirez <antirez@gmail.com>
Sat, 28 Nov 2009 17:19:11 +0000 (18:19 +0100)
committerantirez <antirez@gmail.com>
Sat, 28 Nov 2009 17:19:11 +0000 (18:19 +0100)
test-redis.tcl

index 22e88040da1bf6a7d33517086b1606e4c9b32763..039941d3add28fe46fda688a07859056ea2a22e6 100644 (file)
@@ -1024,6 +1024,45 @@ proc main {server port} {
         $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 {Sorted sets +inf and -inf handling} {
         $r del zset
         $r zadd zset -100 a