more valgrind (and other archs) friendly testing of floating number related features.

This commit is contained in:
antirez 2011-11-16 14:40:50 +01:00
parent cd4aba36cd
commit bf758397a1
3 changed files with 22 additions and 14 deletions

View File

@ -294,3 +294,7 @@ proc csvdump r {
proc csvstring s { proc csvstring s {
return "\"$s\"" return "\"$s\""
} }
proc roundFloat f {
format "%.10g" $f
}

View File

@ -152,13 +152,15 @@ start_server {tags {"basic"}} {
test {INCRBYFLOAT against non existing key} { test {INCRBYFLOAT against non existing key} {
r del novar r del novar
list [r incrbyfloat novar 1] [r get novar] [r incrbyfloat novar 0.25] \ list [roundFloat [r incrbyfloat novar 1]] \
[r get novar] [roundFloat [r get novar]] \
[roundFloat [r incrbyfloat novar 0.25]] \
[roundFloat [r get novar]]
} {1 1 1.25 1.25} } {1 1 1.25 1.25}
test {INCRBYFLOAT against key originally set with SET} { test {INCRBYFLOAT against key originally set with SET} {
r set novar 1.5 r set novar 1.5
r incrbyfloat novar 1.5 roundFloat [r incrbyfloat novar 1.5]
} {3} } {3}
test {INCRBYFLOAT over 32bit value} { test {INCRBYFLOAT over 32bit value} {
@ -213,7 +215,7 @@ start_server {tags {"basic"}} {
test {INCRBYFLOAT decrement} { test {INCRBYFLOAT decrement} {
r set foo 1 r set foo 1
r incrbyfloat foo -1.1 roundFloat [r incrbyfloat foo -1.1]
} {-0.1} } {-0.1}
test "SETNX target key missing" { test "SETNX target key missing" {

View File

@ -327,30 +327,32 @@ start_server {tags {"hash"}} {
set rv {} set rv {}
r hdel smallhash tmp r hdel smallhash tmp
r hdel bighash tmp r hdel bighash tmp
lappend rv [r hincrbyfloat smallhash tmp 2.5] lappend rv [roundFloat [r hincrbyfloat smallhash tmp 2.5]]
lappend rv [r hget smallhash tmp] lappend rv [roundFloat [r hget smallhash tmp]]
lappend rv [r hincrbyfloat bighash tmp 2.5] lappend rv [roundFloat [r hincrbyfloat bighash tmp 2.5]]
lappend rv [r hget bighash tmp] lappend rv [roundFloat [r hget bighash tmp]]
} {2.5 2.5 2.5 2.5} } {2.5 2.5 2.5 2.5}
test {HINCRBYFLOAT against hash key created by hincrby itself} { test {HINCRBYFLOAT against hash key created by hincrby itself} {
set rv {} set rv {}
lappend rv [r hincrbyfloat smallhash tmp 3.5] lappend rv [roundFloat [r hincrbyfloat smallhash tmp 3.5]]
lappend rv [r hget smallhash tmp] lappend rv [roundFloat [r hget smallhash tmp]]
lappend rv [r hincrbyfloat bighash tmp 3.5] lappend rv [roundFloat [r hincrbyfloat bighash tmp 3.5]]
lappend rv [r hget bighash tmp] lappend rv [roundFloat [r hget bighash tmp]]
} {6 6 6 6} } {6 6 6 6}
test {HINCRBYFLOAT against hash key originally set with HSET} { test {HINCRBYFLOAT against hash key originally set with HSET} {
r hset smallhash tmp 100 r hset smallhash tmp 100
r hset bighash tmp 100 r hset bighash tmp 100
list [r hincrbyfloat smallhash tmp 2.5] [r hincrbyfloat bighash tmp 2.5] list [roundFloat [r hincrbyfloat smallhash tmp 2.5]] \
[roundFloat [r hincrbyfloat bighash tmp 2.5]]
} {102.5 102.5} } {102.5 102.5}
test {HINCRBYFLOAT over 32bit value} { test {HINCRBYFLOAT over 32bit value} {
r hset smallhash tmp 17179869184 r hset smallhash tmp 17179869184
r hset bighash tmp 17179869184 r hset bighash tmp 17179869184
list [r hincrbyfloat smallhash tmp 1] [r hincrbyfloat bighash tmp 1] list [r hincrbyfloat smallhash tmp 1] \
[r hincrbyfloat bighash tmp 1]
} {17179869185 17179869185} } {17179869185 17179869185}
test {HINCRBYFLOAT over 32bit value with over 32bit increment} { test {HINCRBYFLOAT over 32bit value with over 32bit increment} {