void dic_destroy (str_node *node) { if (!node) return; dic_destroy(node->left); dic_destroy(node->right); free(node); }
int t_dic_add__new_item__added() { dictionary *dic = dic_new_withint(str_duplicator, free); int key = 3; char str[] = "test1"; int retval; retval = dic_add(dic, &key, str); mu_assert_eq(retval, OK, "dic_add"); mu_assert_eq(dic_count(dic), 1, "count"); dic_destroy(dic, NULL); mu_end; }
int t_dic_lookup__non_existing__returns_null() { dictionary *dic = dic_new_withint(str_duplicator, free); int key = 3; char str[] = "test1"; char *result; dic_add(dic, &key, str); key = 4; result = dic_lookup(dic, &key); mu_assert("value is not null", result == NULL); dic_destroy(dic, NULL); mu_end; }
/* BEGIN TESTS */ int t_dic_lookup__existing__returns_item() { dictionary *dic = dic_new_withint(str_duplicator, free); int key = 3; char str[] = "test1"; char *result; dic_add(dic, &key, str); result = dic_lookup(dic, &key); mu_assert("value is null", result); mu_assert("value is not the same", strcmp(result, str) == 0); dic_destroy(dic, NULL); mu_end; }
int t_dic_remove__existing__removed() { dictionary *dic = dic_new_withint(str_duplicator, free); int key = 3; char str[] = "test1"; int retval, count; dic_add(dic, &key, str); retval = dic_remove(dic, &key); count = dic_count(dic); mu_assert_eq(retval, OK, "retval is not ok"); mu_assert_eq(count, 0, "number of elements is not correct"); dic_destroy(dic, NULL); mu_end; }