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
00aa96f3
Commit
00aa96f3
authored
Apr 16, 2014
by
antirez
Browse files
More HyperLogLog tests.
parent
a3848a74
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/unit/hyperloglog.tcl
View file @
00aa96f3
...
@@ -39,6 +39,82 @@ start_server {tags {"hll"}} {
...
@@ -39,6 +39,82 @@ start_server {tags {"hll"}} {
set res
set res
}
{
5 10
}
}
{
5 10
}
test
{
HyperLogLogs are promote from sparse to dense
}
{
r del hll
r config set hll-sparse-max-bytes 3000
set n 0
while
{
$n
< 100000
}
{
set elements
{}
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
lappend elements
[
expr rand
()]}
incr n 100
r pfadd hll
{*}
$elements
set card
[
r pfcount hll
]
set err
[
expr
{
abs
(
$card-$n
)}]
assert
{
$err
<
(
double
(
$card
)
/100
)
*5
}
if
{
$n
< 1000
}
{
assert
{[
r pfdebug encoding hll
]
eq
{
sparse
}}
}
elseif
{
$n
> 10000
}
{
assert
{[
r pfdebug encoding hll
]
eq
{
dense
}}
}
}
}
test
{
HyperLogLog sparse encoding stress test
}
{
for
{
set x 0
}
{
$x
< 1000
}
{
incr x
}
{
r del hll1 hll2
set numele
[
randomInt 100
]
set elements
{}
for
{
set j 0
}
{
$j
< $numele
}
{
incr j
}
{
lappend elements
[
expr rand
()]
}
# Force dense representation of hll2
r pfadd hll2
r pfdebug todense hll2
r pfadd hll1
{*}
$elements
r pfadd hll2
{*}
$elements
assert
{[
r pfdebug encoding hll1
]
eq
{
sparse
}}
assert
{[
r pfdebug encoding hll2
]
eq
{
dense
}}
# Cardinality estimated should match exactly.
assert
{[
r pfcount hll1
]
eq
[
r pfcount hll2
]}
}
}
test
{
Corrupted sparse HyperLogLogs are detected: Additionl at tail
}
{
r del hll
r pfadd hll a b c
r append hll
"hello"
set e
{}
catch
{
r pfcount hll
}
e
set e
}
{
*INVALIDOBJ*
}
test
{
Corrupted sparse HyperLogLogs are detected: Broken magic
}
{
r del hll
r pfadd hll a b c
r setrange hll 0
"0123"
set e
{}
catch
{
r pfcount hll
}
e
set e
}
{
*WRONGTYPE*
}
test
{
Corrupted sparse HyperLogLogs are detected: Invalid encoding
}
{
r del hll
r pfadd hll a b c
r setrange hll 4
"x"
set e
{}
catch
{
r pfcount hll
}
e
set e
}
{
*WRONGTYPE*
}
test
{
Corrupted dense HyperLogLogs are detected: Wrong length
}
{
r del hll
r pfadd hll a b c
r setrange hll 4
"
\x00
"
set e
{}
catch
{
r pfcount hll
}
e
set e
}
{
*WRONGTYPE*
}
test
{
PFADD, PFCOUNT, PFMERGE type checking works
}
{
test
{
PFADD, PFCOUNT, PFMERGE type checking works
}
{
r set foo bar
r set foo bar
catch
{
r pfadd foo 1
}
e
catch
{
r pfadd foo 1
}
e
...
...
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