Copilot commented on code in PR #3163:
URL: https://github.com/apache/kvrocks/pull/3163#discussion_r2406949634
##########
tests/gocase/unit/type/tdigest/tdigest_test.go:
##########
@@ -518,4 +519,55 @@ func tdigestTests(t *testing.T, configs
util.KvrocksServerConfigs) {
validation(newDestKey1)
validation(newDestKey2)
})
+ t.Run("tdigest.cdf with different arguments", func(t *testing.T) {
+ keyPrefix := "tdigest_cdf_"
+
+ require.ErrorContains(t, rdb.Do(ctx, "TDIGEST.CDF").Err(),
errMsgWrongNumberArg)
+ require.ErrorContains(t, rdb.Do(ctx, "TDIGEST.CDF",
keyPrefix+"key1").Err(), errMsgWrongNumberArg)
+
+ // non-existent key
+ require.ErrorContains(t, rdb.Do(ctx, "TDIGEST.CDF",
keyPrefix+"nonexistent", "1.0").Err(), errMsgKeyNotExist)
+
+ // invalid float value
+ require.ErrorContains(t, rdb.Do(ctx, "TDIGEST.CDF",
keyPrefix+"key2", "invalid").Err(), errValueIsNotFloat)
+
+ // create a tdigest and add some data
+ tdigestKey := keyPrefix + "source"
+ require.NoError(t, rdb.Do(ctx, "TDIGEST.CREATE",
tdigestKey).Err())
+ require.NoError(t, rdb.Do(ctx, "TDIGEST.ADD", tdigestKey,
"1.0", "2.0", "3.0", "4.0", "5.0").Err())
+
+ // single-value CDF query
+ rsp := rdb.Do(ctx, "TDIGEST.CDF", tdigestKey, "3.0")
+ require.NoError(t, rsp.Err())
+ vals, err := rsp.Slice()
+ require.NoError(t, err)
+ require.Len(t, vals, 1)
+ require.NotEqual(t, "nan", vals[0])
+
+ // multi-value CDF query
+ rsp = rdb.Do(ctx, "TDIGEST.CDF", tdigestKey, "0.0", "2.5",
"5.0", "10.0")
+ require.NoError(t, rsp.Err())
+ vals, err = rsp.Slice()
+ require.NoError(t, err)
+ require.Len(t, vals, 4)
+
+ // empty tdigest should return "nan"
+ emptyKey := keyPrefix + "empty"
+ require.NoError(t, rdb.Do(ctx, "TDIGEST.CREATE",
emptyKey).Err())
+ rsp = rdb.Do(ctx, "TDIGEST.CDF", emptyKey, "1.0")
+ require.NoError(t, rsp.Err())
+ vals, err = rsp.Slice()
+ require.NoError(t, err)
+ require.Len(t, vals, 1)
+ require.Equal(t, "nan", vals[0])
+
+ // testing with a empry digest with multi-valued CDF
Review Comment:
Corrected spelling of 'empry' to 'empty'.
```suggestion
// testing with an empty digest with multi-valued CDF
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]