From 3c3d49f3b2f9eec7a6cfebd4ad8bacaa6a8efa10 Mon Sep 17 00:00:00 2001 From: Hristo Staykov Date: Mon, 16 Mar 2026 12:32:45 +0200 Subject: [PATCH] Add encoding-specific APPROX and APPROX+LIMIT tests for SUNIONCARD The existing APPROX tests only used string-element sets (hashtable encoding). The HLL path has a distinct code branch for intset-encoded sets where elements are converted via ll2string() before being fed to hllAdd(). Add tests inside the encoding foreach loop to exercise both regular (listpack/hashtable) and intset encodings for APPROX and APPROX+LIMIT. --- tests/unit/type/set.tcl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/type/set.tcl b/tests/unit/type/set.tcl index 8368cbaeb..8480757da 100644 --- a/tests/unit/type/set.tcl +++ b/tests/unit/type/set.tcl @@ -439,6 +439,18 @@ foreach type {single multiple single_multiple} { assert_equal $expected [r sunioncard 4 nokey1{t} set1{t} set2{t} nokey2{t}] } + test "SUNIONCARD APPROX with two sets - $type" { + set exact [r sunioncard 2 set1{t} set2{t}] + set approx [r sunioncard 2 set1{t} set2{t} APPROX] + set error_pct [expr {abs($approx - $exact) * 100.0 / $exact}] + assert {$error_pct < 5.0} + } + + test "SUNIONCARD APPROX with LIMIT - $type" { + assert_equal 0 [r sunioncard 2 set1{t} set2{t} APPROX LIMIT 0] + assert_equal 10 [r sunioncard 2 set1{t} set2{t} APPROX LIMIT 10] + } + test "SUNIONSTORE with two sets - $type" { r sunionstore setres{t} set1{t} set2{t} assert_encoding $bigenc setres{t}