summaryrefslogtreecommitdiffstats
path: root/nserver/tests/stats_tests.c
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-04-11 02:22:12 -0400
committerrsiddharth <s@ricketyspace.net>2020-04-17 20:56:37 -0400
commit89919c902061006471760cbddd2fe275ff57c8d8 (patch)
tree1eed43518800f434c7585f088ec4e5f77ef36d2e /nserver/tests/stats_tests.c
parent10cc7513914fddbf654e27c795c775a939bc636a (diff)
nserver: Add Stats_unstringify.
* nserver/src/stats.c (Stats_unstringify): New function definition. * nserver/src/stats.h (Stats_unstringify): New function declaration. * nserver/tests/stats_tests.c (tests_stats_unstringify): Test for Stats_unstringify. (tests_stats_unstringify): st_str is now a static variable. Don't free it; it's done in tests_stats_unstringify. (st_str): New static variable.
Diffstat (limited to 'nserver/tests/stats_tests.c')
-rw-r--r--nserver/tests/stats_tests.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/nserver/tests/stats_tests.c b/nserver/tests/stats_tests.c
index e136ab3..3ed92de 100644
--- a/nserver/tests/stats_tests.c
+++ b/nserver/tests/stats_tests.c
@@ -7,6 +7,8 @@
* ../../liblcthw/tests/stats_tests.c
*/
+static char *st_str = NULL;
+
char *test_stats_stringify()
{
Stats *st = Stats_create();
@@ -19,7 +21,7 @@ char *test_stats_stringify()
st->min = 28.3921;
st->max = 238.27;
- char *st_str = Stats_stringify(st);
+ st_str = Stats_stringify(st);
mu_assert(st_str != NULL, "stats stringify failed");
char *expected_st_str = "8238.34:4260238.83:28:28.39:238.27";
@@ -27,17 +29,37 @@ char *test_stats_stringify()
"stringified str invalid");
// cleanup
- free(st_str);
free(st);
return NULL;
}
+char *test_stats_unstringify()
+{
+ mu_assert(st_str != NULL, "st_str not initialized");
+
+ Stats *st = Stats_unstringify(st_str);
+ mu_assert(st != NULL, "stats unstringify failed");
+
+ mu_assert(st->sum == 8238.34, "stats sum incorrect");
+ mu_assert(st->sumsq == 4260238.83, "stats sumsq incorrect");
+ mu_assert(st->n == 28, "stats n incorrect");
+ mu_assert(st->min == 28.39, "stats min incorrect");
+ mu_assert(st->max == 238.27, "stats max incorrect");
+
+ // clean up
+ free(st);
+ free(st_str);
+
+ return NULL;
+}
+
char *all_tests()
{
mu_suite_start();
mu_run_test(test_stats_stringify);
+ mu_run_test(test_stats_unstringify);
return NULL;
}