From dffbbb5a78154d42395284e9b8bf33b236a45599 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 11 Feb 2015 10:12:00 +0100 Subject: [PATCH] SPOP explicit tests for the three different code paths. --- tests/unit/type/set.tcl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/unit/type/set.tcl b/tests/unit/type/set.tcl index 74a8fb31..a9a3d083 100644 --- a/tests/unit/type/set.tcl +++ b/tests/unit/type/set.tcl @@ -346,6 +346,33 @@ start_server { r spop nonexisting_key 100 } {} + test "SPOP new implementation: code path #1" { + set content {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} + create_set myset $content + set res [r spop myset 30] + assert {[lsort $content] eq [lsort $res]} + } + + test "SPOP new implementation: code path #2" { + set content {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} + create_set myset $content + set res [r spop myset 2] + assert {[llength $res] == 2} + assert {[r scard myset] == 18} + set union [concat [r smembers myset] $res] + assert {[lsort $union] eq [lsort $content]} + } + + test "SPOP new implementation: code path #3" { + set content {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} + create_set myset $content + set res [r spop myset 18] + assert {[llength $res] == 18} + assert {[r scard myset] == 2} + set union [concat [r smembers myset] $res] + assert {[lsort $union] eq [lsort $content]} + } + test "SRANDMEMBER with against non existing key" { r srandmember nonexisting_key 100 } {}