Skip to content

Commit

Permalink
Add fuzzy test for SETBIT
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Dec 15, 2010
1 parent 30407e1 commit e983cf3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/unit/basic.tcl
Expand Up @@ -422,6 +422,24 @@ start_server {tags {"basic"}} {
assert_error "*out of range*" {r setbit mykey 0 20}
}

test "SETBIT fuzzing" {
set str ""
set len [expr 256*8]
r del mykey

for {set i 0} {$i < 2000} {incr i} {
set bitnum [randomInt $len]
set bitval [randomInt 2]
set fmt [format "%%-%ds%%d%%-s" $bitnum]
set head [string range $str 0 $bitnum-1]
set tail [string range $str $bitnum+1 end]
set str [string map {" " 0} [format $fmt $head $bitval $tail]]

r setbit mykey $bitnum $bitval
assert_equal [binary format B* $str] [r get mykey]
}
}

test "GETBIT against non-existing key" {
r del mykey
assert_equal 0 [r getbit mykey 0]
Expand Down

0 comments on commit e983cf3

Please sign in to comment.