Test: ZADD NX and XX options tests

This commit is contained in:
antirez 2015-05-29 11:23:49 +02:00
parent c043a4e6f4
commit 910e72d1c1

View File

@ -43,6 +43,63 @@ start_server {tags {"zset"}} {
assert_error "*not*float*" {r zadd myzset nan abc}
}
test "ZADD with options syntax error with incomplete pair" {
r del ztmp
catch {r zadd ztmp xx 10 x 20} err
set err
} {ERR*}
test "ZADD XX option without key - $encoding" {
r del ztmp
assert {[r zadd ztmp xx 10 x] == 0}
assert {[r type ztmp] eq {none}}
}
test "ZADD XX existing key - $encoding" {
r del ztmp
r zadd ztmp 10 x
assert {[r zadd ztmp xx 20 y] == 0}
assert {[r zcard ztmp] == 1}
}
test "ZADD XX returns the number of elements actually added" {
r del ztmp
r zadd ztmp 10 x
set retval [r zadd ztmp 10 x 20 y 30 z]
assert {$retval == 2}
}
test "ZADD XX updates existing elements score" {
r del ztmp
r zadd ztmp 10 x 20 y 30 z
r zadd ztmp xx 5 foo 11 x 21 y 40 zap
assert {[r zcard ztmp] == 3}
assert {[r zscore ztmp x] == 11}
assert {[r zscore ztmp y] == 21}
}
test "ZADD XX and NX are not compatible" {
r del ztmp
catch {r zadd ztmp xx nx 10 x} err
set err
} {ERR*}
test "ZADD NX with non exisitng key" {
r del ztmp
r zadd ztmp nx 10 x 20 y 30 z
assert {[r zcard ztmp] == 3}
}
test "ZADD NX only add new elements without updating old ones" {
r del ztmp
r zadd ztmp 10 x 20 y 30 z
assert {[r zadd ztmp nx 11 x 21 y 100 a 200 b] == 2}
assert {[r zscore ztmp x] == 10}
assert {[r zscore ztmp y] == 20}
assert {[r zscore ztmp a] == 100}
assert {[r zscore ztmp b] == 200}
}
test "ZINCRBY calls leading to NaN result in error" {
r zincrby myzset +inf abc
assert_error "*NaN*" {r zincrby myzset -inf abc}
@ -77,6 +134,8 @@ start_server {tags {"zset"}} {
}
test "ZCARD basics - $encoding" {
r del ztmp
r zadd ztmp 10 a 20 b 30 c
assert_equal 3 [r zcard ztmp]
assert_equal 0 [r zcard zdoesntexist]
}