Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
8b8c1cd4
Commit
8b8c1cd4
authored
Feb 27, 2014
by
antirez
Browse files
BITPOS fuzzy testing.
parent
b21f4d63
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/unit/bitops.tcl
View file @
8b8c1cd4
...
...
@@ -303,6 +303,39 @@ start_server {tags {"bitops"}} {
test
{
BITPOS bit=0 changes behavior if end is given
}
{
r set str
"
\xff\xff\xff
"
assert
{[
r bitpos str 0
]
== 24
}
assert
{[
r bitpos str 0 0
]
== 24
}
assert
{[
r bitpos str 0 0 -1
]
== -1
}
}
test
{
BITPOS bit=1 fuzzy testing using SETBIT
}
{
r del str
set max 524288
;
# 64k
set first_one_pos -1
for
{
set j 0
}
{
$j
< 1000
}
{
incr j
}
{
assert
{[
r bitpos str 1
]
== $first_one_pos
}
set pos
[
randomInt $max
]
r setbit str $pos 1
if
{
$first
_one_pos == -1 || $first_one_pos > $pos
}
{
# Update the position of the first 1 bit in the array
# if the bit we set is on the left of the previous one.
set first_one_pos $pos
}
}
}
test
{
BITPOS bit=0 fuzzy testing using SETBIT
}
{
set max 524288
;
# 64k
set first_zero_pos $max
r set str
[
string repeat
"
\xff
"
[
expr $max/8
]]
for
{
set j 0
}
{
$j
< 1000
}
{
incr j
}
{
assert
{[
r bitpos str 0
]
== $first_zero_pos
}
set pos
[
randomInt $max
]
r setbit str $pos 0
if
{
$first
_zero_pos > $pos
}
{
# Update the position of the first 0 bit in the array
# if the bit we clear is on the left of the previous one.
set first_zero_pos $pos
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment