summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-11-03 19:03:09 +0100
committerantirez <antirez@gmail.com>2015-11-03 19:03:17 +0100
commit30b324698f9ff0c3b49357d2e1977c1f4fa83063 (patch)
tree5442b68ebbe33e5d0483424aab5415acab3a92f9 /tests/unit
parent77362b9027133e2a35e7b7f816133c60aab12087 (diff)
downloadredis-30b324698f9ff0c3b49357d2e1977c1f4fa83063.tar.gz
Test: improve PFCOUNT with multiple keys testing.
An user raised a question about a given behavior of PFCOUNT. Added a test to show the behavior (union) is correct when most of the items are in common.
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/hyperloglog.tcl19
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/unit/hyperloglog.tcl b/tests/unit/hyperloglog.tcl
index 3f5142076..7d36b7a35 100644
--- a/tests/unit/hyperloglog.tcl
+++ b/tests/unit/hyperloglog.tcl
@@ -136,10 +136,9 @@ start_server {tags {"hll"}} {
r pfcount hll
} {5}
- test {PFCOUNT multiple-keys merge returns cardinality of union} {
+ test {PFCOUNT multiple-keys merge returns cardinality of union #1} {
r del hll1 hll2 hll3
for {set x 1} {$x < 10000} {incr x} {
- # Force dense representation of hll2
r pfadd hll1 "foo-$x"
r pfadd hll2 "bar-$x"
r pfadd hll3 "zap-$x"
@@ -151,6 +150,22 @@ start_server {tags {"hll"}} {
}
}
+ test {PFCOUNT multiple-keys merge returns cardinality of union #2} {
+ r del hll1 hll2 hll3
+ set elements {}
+ for {set x 1} {$x < 10000} {incr x} {
+ for {set j 1} {$j <= 3} {incr j} {
+ set rint [randomInt 20000]
+ r pfadd hll$j $rint
+ lappend elements $rint
+ }
+ }
+ set realcard [llength [lsort -unique $elements]]
+ set card [r pfcount hll1 hll2 hll3]
+ set err [expr {abs($card-$realcard)}]
+ assert {$err < (double($card)/100)*5}
+ }
+
test {PFDEBUG GETREG returns the HyperLogLog raw registers} {
r del hll
r pfadd hll 1 2 3