Skip to content

Commit

Permalink
Enhancement: ZPOPMIN command tests to check outputs with ZCOUNT comma…
Browse files Browse the repository at this point in the history
…nd (DiceDB#1225)
  • Loading branch information
surya0180 authored Nov 6, 2024
1 parent 3866213 commit 5067809
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 43 deletions.
22 changes: 14 additions & 8 deletions integration_tests/commands/http/zset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestZPOPMIN(t *testing.T) {
commands: []HTTPCommand{
{Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "member1", "2", "member2", "3", "member3"}}},
{Command: "ZPOPMIN", Body: map[string]interface{}{"key": "myzset"}},
{Command: "ZCOUNT", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "2.98"}}},
},
expected: []interface{}{float64(3), []interface{}{"member1", "1"}, float64(1)},
},
Expand All @@ -37,14 +38,16 @@ func TestZPOPMIN(t *testing.T) {
commands: []HTTPCommand{
{Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "member1", "2", "member2", "3", "member3"}}},
{Command: "ZPOPMIN", Body: map[string]interface{}{"key": "myzset", "value": int64(2)}},
{Command: "ZCOUNT", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"0.44", "2"}}},
},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "2"}, float64(1)},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "2"}, float64(0)},
},
{
name: "ZPOPMIN with count argument but multiple members have the same score",
commands: []HTTPCommand{
{Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "member1", "1", "member2", "1", "member3"}}},
{Command: "ZPOPMIN", Body: map[string]interface{}{"key": "myzset", "value": int64(2)}},
{Command: "ZCOUNT", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "2"}}},
},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "1"}, float64(1)},
},
Expand All @@ -53,14 +56,16 @@ func TestZPOPMIN(t *testing.T) {
commands: []HTTPCommand{
{Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "member1", "2", "member2", "3", "member3"}}},
{Command: "ZPOPMIN", Body: map[string]interface{}{"key": "myzset", "value": int64(-1)}},
{Command: "ZCOUNT", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "1000"}}},
},
expected: []interface{}{float64(3), []interface{}{}, float64(1)},
expected: []interface{}{float64(3), []interface{}{}, float64(3)},
},
{
name: "ZPOPMIN with invalid count argument",
commands: []HTTPCommand{
{Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "member1"}}},
{Command: "ZPOPMIN", Body: map[string]interface{}{"key": "myzset", "value": "INCORRECT_COUNT_ARGUMENT"}},
{Command: "ZCOUNT", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "2"}}},
},
expected: []interface{}{float64(1), "ERR value is not an integer or out of range", float64(1)},
},
Expand All @@ -69,8 +74,9 @@ func TestZPOPMIN(t *testing.T) {
commands: []HTTPCommand{
{Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "member1", "2", "member2", "3", "member3"}}},
{Command: "ZPOPMIN", Body: map[string]interface{}{"key": "myzset", "value": int64(10)}},
{Command: "ZCOUNT", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1", "2"}}},
},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "2", "member3", "3"}, float64(1)},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "2", "member3", "3"}, float64(0)},
},
{
name: "ZPOPMIN on empty sorted set",
Expand All @@ -86,22 +92,22 @@ func TestZPOPMIN(t *testing.T) {
commands: []HTTPCommand{
{Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1.5", "member1", "2.7", "member2", "3.8", "member3"}}},
{Command: "ZPOPMIN", Body: map[string]interface{}{"key": "myzset"}},
{Command: "ZCOUNT", Body: map[string]interface{}{"key": "myzset", "values": [...]string{"1.3", "3.6"}}},
},
expected: []interface{}{float64(3), []interface{}{"member1", "1.5"}, float64(1)},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
exec.FireCommand(HTTPCommand{
Command: "DEL",
Body: map[string]interface{}{"key": "myzset"},
})
for i, cmd := range tc.commands {
result, _ := exec.FireCommand(cmd)

assert.Equal(t, tc.expected[i], result)
}
exec.FireCommand(HTTPCommand{
Command: "DEL",
Body: map[string]interface{}{"key": "myzset"},
})
})
}
}
Expand Down
34 changes: 17 additions & 17 deletions integration_tests/commands/resp/zset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,53 @@ func TestZPOPMIN(t *testing.T) {
},
{
name: "ZPOPMIN on existing key (without count argument)",
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset"},
expected: []interface{}{int64(3), []interface{}{"member1", "1"}},
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset", "ZCOUNT myzset 1 10"},
expected: []interface{}{int64(3), []interface{}{"member1", "1"}, int64(2)},
},
{
name: "ZPOPMIN with normal count argument",
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset 2"},
expected: []interface{}{int64(3), []interface{}{"member1", "1", "member2", "2"}},
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset 2", "ZCOUNT myzset 1 2"},
expected: []interface{}{int64(3), []interface{}{"member1", "1", "member2", "2"}, int64(0)},
},
{
name: "ZPOPMIN with count argument but multiple members have the same score",
commands: []string{"ZADD myzset 1 member1 1 member2 1 member3", "ZPOPMIN myzset 2"},
expected: []interface{}{int64(3), []interface{}{"member1", "1", "member2", "1"}},
commands: []string{"ZADD myzset 1 member1 1 member2 1 member3", "ZPOPMIN myzset 2", "ZCOUNT myzset 1 1"},
expected: []interface{}{int64(3), []interface{}{"member1", "1", "member2", "1"}, int64(1)},
},
{
name: "ZPOPMIN with negative count argument",
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset -1"},
expected: []interface{}{int64(3), []interface{}{}},
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset -1", "ZCOUNT myzset 0.6 3.231"},
expected: []interface{}{int64(3), []interface{}{}, int64(3)},
},
{
name: "ZPOPMIN with invalid count argument",
commands: []string{"ZADD myzset 1 member1", "ZPOPMIN myzset INCORRECT_COUNT_ARGUMENT"},
expected: []interface{}{int64(1), "ERR value is not an integer or out of range"},
commands: []string{"ZADD myzset 1 member1", "ZPOPMIN myzset INCORRECT_COUNT_ARGUMENT", "ZCOUNT myzset 1 10"},
expected: []interface{}{int64(1), "ERR value is not an integer or out of range", int64(1)},
},
{
name: "ZPOPMIN with count argument greater than length of sorted set",
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset 10"},
expected: []interface{}{int64(3), []interface{}{"member1", "1", "member2", "2", "member3", "3"}},
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset 10", "ZCOUNT myzset 1 10"},
expected: []interface{}{int64(3), []interface{}{"member1", "1", "member2", "2", "member3", "3"}, int64(0)},
},
{
name: "ZPOPMIN on empty sorted set",
commands: []string{"ZADD myzset 1 member1", "ZPOPMIN myzset 1", "ZPOPMIN myzset"},
expected: []interface{}{int64(1), []interface{}{"member1", "1"}, []interface{}{}},
commands: []string{"ZADD myzset 1 member1", "ZPOPMIN myzset 1", "ZPOPMIN myzset", "ZCOUNT myzset 0 10000"},
expected: []interface{}{int64(1), []interface{}{"member1", "1"}, []interface{}{}, int64(0)},
},
{
name: "ZPOPMIN with floating-point scores",
commands: []string{"ZADD myzset 1.5 member1 2.7 member2 3.8 member3", "ZPOPMIN myzset"},
expected: []interface{}{int64(3), []interface{}{"member1", "1.5"}},
commands: []string{"ZADD myzset 1.5 member1 2.7 member2 3.8 member3", "ZPOPMIN myzset", "ZCOUNT myzset 1.499 2.711"},
expected: []interface{}{int64(3), []interface{}{"member1", "1.5"}, int64(1)},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
FireCommand(conn, "DEL myzset")
for i, cmd := range tc.commands {
result := FireCommand(conn, cmd)
assert.Equal(t, tc.expected[i], result)
}
FireCommand(conn, "DEL myzset")
})
}
}
Expand Down
35 changes: 17 additions & 18 deletions integration_tests/commands/websocket/zset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,56 @@ func TestZPOPMIN(t *testing.T) {
},
{
name: "ZPOPMIN on existing key (without count argument)",
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset"},
expected: []interface{}{float64(3), []interface{}{"member1", "1"}},
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset", "ZCOUNT myzset 1 10"},
expected: []interface{}{float64(3), []interface{}{"member1", "1"}, float64(2)},
},
{
name: "ZPOPMIN with normal count argument",
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset 2"},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "2"}},
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset 2", "ZCOUNT myzset 1 2"},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "2"}, float64(0)},
},
{
name: "ZPOPMIN with count argument but multiple members have the same score",
commands: []string{"ZADD myzset 1 member1 1 member2 1 member3", "ZPOPMIN myzset 2"},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "1"}},
commands: []string{"ZADD myzset 1 member1 1 member2 1 member3", "ZPOPMIN myzset 2", "ZCOUNT myzset 1 1"},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "1"}, float64(1)},
},
{
name: "ZPOPMIN with negative count argument",
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset -1"},
expected: []interface{}{float64(3), []interface{}{}},
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset -1", "ZCOUNT myzset 0.6 3.231"},
expected: []interface{}{float64(3), []interface{}{}, float64(3)},
},
{
name: "ZPOPMIN with invalid count argument",
commands: []string{"ZADD myzset 1 member1", "ZPOPMIN myzset INCORRECT_COUNT_ARGUMENT"},
expected: []interface{}{float64(1), "ERR value is not an integer or out of range"},
commands: []string{"ZADD myzset 1 member1", "ZPOPMIN myzset INCORRECT_COUNT_ARGUMENT", "ZCOUNT myzset 1 10"},
expected: []interface{}{float64(1), "ERR value is not an integer or out of range", float64(1)},
},
{
name: "ZPOPMIN with count argument greater than length of sorted set",
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset 10"},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "2", "member3", "3"}},
commands: []string{"ZADD myzset 1 member1 2 member2 3 member3", "ZPOPMIN myzset 10", "ZCOUNT myzset 1 10"},
expected: []interface{}{float64(3), []interface{}{"member1", "1", "member2", "2", "member3", "3"}, float64(0)},
},
{
name: "ZPOPMIN on empty sorted set",
commands: []string{"ZADD myzset 1 member1", "ZPOPMIN myzset 1", "ZPOPMIN myzset"},
expected: []interface{}{float64(1), []interface{}{"member1", "1"}, []interface{}{}},
commands: []string{"ZADD myzset 1 member1", "ZPOPMIN myzset 1", "ZPOPMIN myzset", "ZCOUNT myzset 0 10000"},
expected: []interface{}{float64(1), []interface{}{"member1", "1"}, []interface{}{}, float64(0)},
},
{
name: "ZPOPMIN with floating-point scores",
commands: []string{"ZADD myzset 1.5 member1 2.7 member2 3.8 member3", "ZPOPMIN myzset"},
expected: []interface{}{float64(3), []interface{}{"member1", "1.5"}},
commands: []string{"ZADD myzset 1.5 member1 2.7 member2 3.8 member3", "ZPOPMIN myzset", "ZCOUNT myzset 1.499 2.711"},
expected: []interface{}{float64(3), []interface{}{"member1", "1.5"}, float64(1)},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
conn := exec.ConnectToServer()

DeleteKey(t, conn, exec, "myzset")

for i, cmd := range tc.commands {
result, err := exec.FireCommandAndReadResponse(conn, cmd)
assert.Nil(t, err)
assert.Equal(t, tc.expected[i], result)
}
DeleteKey(t, conn, exec, "myzset")
})
}
}
Expand Down

0 comments on commit 5067809

Please sign in to comment.