From 2a7847a3b5732667f1b63a12f6cdbd25285dccf8 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 27 Feb 2014 10:00:17 +0100 Subject: [PATCH] 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. --- tests/unit/bitops.tcl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/unit/bitops.tcl b/tests/unit/bitops.tcl index dade8923..a145199a 100644 --- a/tests/unit/bitops.tcl +++ b/tests/unit/bitops.tcl @@ -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} { set str [randstring 0 3000] 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} { r set s "foobar" assert_equal [r bitcount s 0 -1] [count_bits "foobar"]