BITCOUNT fuzzy test with random start/end added.

It was verified in practice that this test is able to stress much more
the implementation by introducing errors that were only trivially to
detect with different offsets but impossible to detect starting always
at zero and counting bits the full length of the string.
This commit is contained in:
antirez 2014-02-27 10:00:17 +01:00
parent 30a92b6c76
commit a3eb3f9c3b

View File

@ -52,7 +52,7 @@ start_server {tags {"bitops"}} {
} }
} }
test {BITCOUNT fuzzing} { test {BITCOUNT fuzzing without start/end} {
for {set j 0} {$j < 100} {incr j} { for {set j 0} {$j < 100} {incr j} {
set str [randstring 0 3000] set str [randstring 0 3000]
r set str $str r set str $str
@ -60,6 +60,20 @@ start_server {tags {"bitops"}} {
} }
} }
test {BITCOUNT fuzzing with start/end} {
for {set j 0} {$j < 100} {incr j} {
set str [randstring 0 3000]
r set str $str
set l [string length $str]
set start [randomInt $l]
set end [randomInt $l]
if {$start > $end} {
lassign [list $end $start] start end
}
assert {[r bitcount str $start $end] == [count_bits [string range $str $start $end]]}
}
}
test {BITCOUNT with start, end} { test {BITCOUNT with start, end} {
r set s "foobar" r set s "foobar"
assert_equal [r bitcount s 0 -1] [count_bits "foobar"] assert_equal [r bitcount s 0 -1] [count_bits "foobar"]