From 951213e2d270c58ad776c6be49ee9e9bb8acc5d0 Mon Sep 17 00:00:00 2001 From: antirez Date: Sun, 20 May 2012 11:03:54 +0200 Subject: [PATCH] Bit operations tests improved. Fuzzing tests of BITCOUNT / BITOP are iterated multiple times. The new BITCOUNT fuzzing test uses random strings in a wider interval of lengths including zero-len strings. --- tests/unit/bitops.tcl | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/unit/bitops.tcl b/tests/unit/bitops.tcl index c072f545..bc479943 100644 --- a/tests/unit/bitops.tcl +++ b/tests/unit/bitops.tcl @@ -44,11 +44,7 @@ start_server {tags {"bitops"}} { } 0 catch {unset num} - foreach vec [list \ - "" "\xaa" "\x00\x00\xff" "foobar" \ - [randstring 2000 3000] [randstring 2000 3000] \ - [randstring 2000 3000] \ - ] { + foreach vec [list "" "\xaa" "\x00\x00\xff" "foobar"] { incr num test "BITCOUNT against test vector #$num" { r set str $vec @@ -56,6 +52,14 @@ start_server {tags {"bitops"}} { } } + test {BITCOUNT fuzzing} { + for {set j 0} {$j < 100} {incr j} { + set str [randstring 0 3000] + r set str $str + assert {[r bitcount str] == [count_bits $str]} + } + } + test {BITCOUNT with start, end} { r set s "foobar" assert_equal [r bitcount s 0 -1] [count_bits "foobar"] @@ -114,17 +118,19 @@ start_server {tags {"bitops"}} { foreach op {and or xor} { test "BITOP $op fuzzing" { - set vec {} - set veckeys {} - set numvec [expr {[randomInt 10]+1}] - for {set j 0} {$j < $numvec} {incr j} { - set str [randstring 0 1000] - lappend vec $str - lappend veckeys vector_$j - r set vector_$j $str + for {set i 0} {$i < 10} {incr i} { + set vec {} + set veckeys {} + set numvec [expr {[randomInt 10]+1}] + for {set j 0} {$j < $numvec} {incr j} { + set str [randstring 0 1000] + lappend vec $str + lappend veckeys vector_$j + r set vector_$j $str + } + r bitop $op target {*}$veckeys + assert_equal [r get target] [simulate_bit_op $op {*}$vec] } - r bitop $op target {*}$veckeys - assert_equal [r get target] [simulate_bit_op $op {*}$vec] } } } -- 2.45.2