Ejemplo n.º 1
0
void dic_destroy (str_node *node) {
    if (!node)
        return;

    dic_destroy(node->left);
    dic_destroy(node->right);

    free(node);
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
/* 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;
}
Ejemplo n.º 5
0
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;
}