Commit 2a7847a3 authored by antirez's avatar antirez
Browse files

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.
parent 746ce35f
...@@ -52,7 +52,7 @@ start_server {tags {"bitops"}} { ...@@ -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"}} { ...@@ -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"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment