nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 0cb98cf1fd7368c2f03821f62f5ab4e9cf07613e
parent c4b34755401eae260c5090588db056b2a2ad49ce
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon,  6 Jan 2020 19:49:46 -0500

nserver: protocol.h: Update sssample.

* nserver/src/protocol.c (sssample):  Return mean on success.
* nserver/src/protocol.h (sssample): Change return data type to
double.
* nserver/tests/protocol_tests.c (test_sssample): Update test.

Diffstat:
nserver/src/protocol.c | 7+++++--
nserver/src/protocol.h | 2+-
nserver/tests/protocol_tests.c | 30+++++++++++++++---------------
3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c @@ -64,7 +64,7 @@ int ssdelete(char *key) return -1; } -int sssample(char *key, double s) +double sssample(char *key, double s) { check(hash != NULL, "hash not initialized"); @@ -79,7 +79,10 @@ int sssample(char *key, double s) // 3. sample! Stats_sample(st, s); - return 0; + // 4. get mean. + double m = Stats_mean(st); + + return m; error: return -1; } diff --git a/nserver/src/protocol.h b/nserver/src/protocol.h @@ -10,7 +10,7 @@ int sscreate(char *key); int ssdelete(char *key); -int sssample(char *key, double s); +double sssample(char *key, double s); double ssmean(char *key); char *ssdump(char *key); char *sslist(); diff --git a/nserver/tests/protocol_tests.c b/nserver/tests/protocol_tests.c @@ -16,28 +16,28 @@ char *test_sscreate() char *test_sssample() { - int rc = 0; + double mean = 0; - rc = sssample("crimson", 3); - mu_assert(rc == 0, "sssample failed 0"); + mean = sssample("crimson", 3); + mu_assert(mean == 3.0, "sssample failed 0"); - rc = sssample("crimson", 9); - mu_assert(rc == 0, "sssample failed 1"); + mean = sssample("crimson", 9); + mu_assert(mean == 6.0, "sssample failed 1"); - rc = sssample("crimson", 12); - mu_assert(rc == 0, "sssample failed 2"); + mean = sssample("crimson", 12); + mu_assert(mean == 8.0, "sssample failed 2"); - rc = sssample("/vermilion", 20); - mu_assert(rc == 0, "sssample failed 3"); + mean = sssample("/vermilion", 20); + mu_assert(mean == 20.0, "sssample failed 3"); - rc = sssample("/vermilion", 27); - mu_assert(rc == 0, "sssample failed 4"); + mean = sssample("/vermilion", 27); + mu_assert(mean == 23.5, "sssample failed 4"); - rc = sssample("/vermilion", 4); - mu_assert(rc == 0, "sssample failed 5"); + mean = sssample("/vermilion", 4); + mu_assert(mean == 17.0, "sssample failed 5"); - rc = sssample("/ruby", 48); - mu_assert(rc == -1, "sssample failed 6"); + mean = sssample("/ruby", 48); + mu_assert(mean == -1, "sssample failed 6"); return NULL; }