From 5b1207c63f235df510547901982a9883ca394f24 Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 28 Nov 2009 18:19:11 +0100 Subject: [PATCH] ZRANGEBYSCORE fuzzy test --- test-redis.tcl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test-redis.tcl b/test-redis.tcl index 22e88040..039941d3 100644 --- a/test-redis.tcl +++ b/test-redis.tcl @@ -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