Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
223a0591
Commit
223a0591
authored
Feb 07, 2010
by
antirez
Browse files
ZCOUNT and ZRANGEBYSCORE new tests
parent
f44dd428
Changes
1
Hide whitespace changes
Inline
Side-by-side
test-redis.tcl
View file @
223a0591
...
@@ -1300,15 +1300,16 @@ proc main {server port} {
...
@@ -1300,15 +1300,16 @@ proc main {server port} {
list $v1 $v2
[
$r
zscore zset foo
]
[
$r
zscore zset bar
]
list $v1 $v2
[
$r
zscore zset foo
]
[
$r
zscore zset bar
]
}
{{
bar foo
}
{
foo bar
}
-2 6
}
}
{{
bar foo
}
{
foo bar
}
-2 6
}
test
{
ZRANGEBYSCORE basics
}
{
test
{
ZRANGEBYSCORE
and ZCOUNT
basics
}
{
$r del zset
$r del zset
$r zadd zset 1 a
$r zadd zset 1 a
$r zadd zset 2 b
$r zadd zset 2 b
$r zadd zset 3 c
$r zadd zset 3 c
$r zadd zset 4 d
$r zadd zset 4 d
$r zadd zset 5 e
$r zadd zset 5 e
$r zrangebyscore zset 2 4
list
[
$r
zrangebyscore zset 2 4
]
[
$r
zrangebyscore zset
(
2
(
4
]
\
}
{
b c d
}
[
$r
zcount zset 2 4
]
[
$r
zcount zset
(
2
(
4
]
}
{{
b c d
}
c 3 1
}
test
{
ZRANGEBYSCORE withscores
}
{
test
{
ZRANGEBYSCORE withscores
}
{
$r del zset
$r del zset
...
@@ -1337,24 +1338,65 @@ proc main {server port} {
...
@@ -1337,24 +1338,65 @@ proc main {server port} {
set low
[
$r
zrangebyscore zset -inf $min
]
set low
[
$r
zrangebyscore zset -inf $min
]
set ok
[
$r
zrangebyscore zset $min $max
]
set ok
[
$r
zrangebyscore zset $min $max
]
set high
[
$r
zrangebyscore zset $max +inf
]
set high
[
$r
zrangebyscore zset $max +inf
]
set lowx
[
$r
zrangebyscore zset -inf
(
$min
]
set okx
[
$r
zrangebyscore zset
(
$min
(
$max
]
set highx
[
$r
zrangebyscore zset
(
$max
+inf
]
if
{[
$r
zcount zset -inf $min
]
!=
[
llength $low
]}
{
append err
"Error, len does not match zcount
\n
"
}
if
{[
$r
zcount zset $min $max
]
!=
[
llength $ok
]}
{
append err
"Error, len does not match zcount
\n
"
}
if
{[
$r
zcount zset $max +inf
]
!=
[
llength $high
]}
{
append err
"Error, len does not match zcount
\n
"
}
if
{[
$r
zcount zset -inf
(
$min
]
!=
[
llength $lowx
]
}
{
append err
"Error, len does not match zcount
\n
"
}
if
{[
$r
zcount zset
(
$min
(
$max
]
!=
[
llength $okx
]
}
{
append err
"Error, len does not match zcount
\n
"
}
if
{[
$r
zcount zset
(
$max
+inf
]
!=
[
llength $highx
]
}
{
append err
"Error, len does not match zcount
\n
"
}
foreach x $low
{
foreach x $low
{
set score
[
$r
zscore zset $x
]
set score
[
$r
zscore zset $x
]
if
{
$score
> $min
}
{
if
{
$score
> $min
}
{
append err
"Error, score for
$x
is
$score
>
$min
\n
"
append err
"Error, score for
$x
is
$score
>
$min
\n
"
}
}
}
}
foreach x $lowx
{
set score
[
$r
zscore zset $x
]
if
{
$score
>= $min
}
{
append err
"Error, score for
$x
is
$score
>=
$min
\n
"
}
}
foreach x $ok
{
foreach x $ok
{
set score
[
$r
zscore zset $x
]
set score
[
$r
zscore zset $x
]
if
{
$score
< $min || $score > $max
}
{
if
{
$score
< $min || $score > $max
}
{
append err
"Error, score for
$x
is
$score
outside
$min-$max
range
\n
"
append err
"Error, score for
$x
is
$score
outside
$min-$max
range
\n
"
}
}
}
}
foreach x $okx
{
set score
[
$r
zscore zset $x
]
if
{
$score
<= $min || $score >= $max
}
{
append err
"Error, score for
$x
is
$score
outside
$min-$max
open range
\n
"
}
}
foreach x $high
{
foreach x $high
{
set score
[
$r
zscore zset $x
]
set score
[
$r
zscore zset $x
]
if
{
$score
< $max
}
{
if
{
$score
< $max
}
{
append err
"Error, score for
$x
is
$score
<
$max
\n
"
append err
"Error, score for
$x
is
$score
<
$max
\n
"
}
}
}
}
foreach x $highx
{
set score
[
$r
zscore zset $x
]
if
{
$score
<= $max
}
{
append err
"Error, score for
$x
is
$score
<=
$max
\n
"
}
}
}
}
set _ $err
set _ $err
}
{}
}
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment