1start_server {tags {"hll"}} { 2 test {HyperLogLog self test passes} { 3 catch {r pfselftest} e 4 set e 5 } {OK} 6 7 test {PFADD without arguments creates an HLL value} { 8 r pfadd hll 9 r exists hll 10 } {1} 11 12 test {Approximated cardinality after creation is zero} { 13 r pfcount hll 14 } {0} 15 16 test {PFADD returns 1 when at least 1 reg was modified} { 17 r pfadd hll a b c 18 } {1} 19 20 test {PFADD returns 0 when no reg was modified} { 21 r pfadd hll a b c 22 } {0} 23 24 test {PFADD works with empty string (regression)} { 25 r pfadd hll "" 26 } 27 28 # Note that the self test stresses much better the 29 # cardinality estimation error. We are testing just the 30 # command implementation itself here. 31 test {PFCOUNT returns approximated cardinality of set} { 32 r del hll 33 set res {} 34 r pfadd hll 1 2 3 4 5 35 lappend res [r pfcount hll] 36 # Call it again to test cached value invalidation. 37 r pfadd hll 6 7 8 8 9 10 38 lappend res [r pfcount hll] 39 set res 40 } {5 10} 41 42 test {PFADD, PFCOUNT, PFMERGE type checking works} { 43 r set foo bar 44 catch {r pfadd foo 1} e 45 assert_match {*WRONGTYPE*} $e 46 catch {r pfcount foo} e 47 assert_match {*WRONGTYPE*} $e 48 catch {r pfmerge bar foo} e 49 assert_match {*WRONGTYPE*} $e 50 catch {r pfmerge foo bar} e 51 assert_match {*WRONGTYPE*} $e 52 } 53 54 test {PFMERGE results on the cardinality of union of sets} { 55 r del hll hll1 hll2 hll3 56 r pfadd hll1 a b c 57 r pfadd hll2 b c d 58 r pfadd hll3 c d e 59 r pfmerge hll hll1 hll2 hll3 60 r pfcount hll 61 } {5} 62 63 test {PFDEBUG GETREG returns the HyperLogLog raw registers} { 64 r del hll 65 r pfadd hll 1 2 3 66 llength [r pfdebug getreg hll] 67 } {16384} 68} 69