/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
for (unsigned i = 0; i < oldsize; i++, currcell++) {
if (*currcell == nullptr) /* empty cell */
for (unsigned i = 0; i < oldsize; i++, currcell++) {
if (*currcell == nullptr) /* empty cell */
{
xbt_test_add("Remove '%s'", key);
xbt_dict_remove(head, key);
{
xbt_test_add("Remove '%s'", key);
xbt_dict_remove(head, key);
- xbt_test_assert(not data || not strcmp(key, data), "Key(%s) != value(%s). Aborting", key, data);
+ xbt_test_assert(key && data && strcmp(key, data) == 0, "Key(%s) != value(%s). Aborting", key, data);
/* RETRIEVE */
xbt_test_add("Search 123");
char* data = (char*)xbt_dict_get(head, "123");
/* RETRIEVE */
xbt_test_add("Search 123");
char* data = (char*)xbt_dict_get(head, "123");
search_not_found(head, "Can't be found");
search_not_found(head, "123 Can't be found");
search_not_found(head, "Can't be found");
search_not_found(head, "123 Can't be found");
xbt_test_log("Fill the struct, count its elems and frees the structure");
xbt_test_log("using 1000 elements with %d chars long randomized keys.", SIZEOFKEY);
xbt_dict_t head = xbt_dict_new_homogeneous(free);
xbt_test_log("Fill the struct, count its elems and frees the structure");
xbt_test_log("using 1000 elements with %d chars long randomized keys.", SIZEOFKEY);
xbt_dict_t head = xbt_dict_new_homogeneous(free);
for (int k = 0; k < SIZEOFKEY - 1; k++)
key[k] = rand() % ('z' - 'a') + 'a';
key[SIZEOFKEY - 1] = '\0';
for (int k = 0; k < SIZEOFKEY - 1; k++)
key[k] = rand() % ('z' - 'a') + 'a';
key[SIZEOFKEY - 1] = '\0';
data = (char*) xbt_dict_get_or_null(head, key);
} while (data != nullptr);
data = (char*) xbt_dict_get_or_null(head, key);
} while (data != nullptr);
snprintf(key,10, "%d", j);
xbt_dict_set(head, key, key, nullptr);
}
snprintf(key,10, "%d", j);
xbt_dict_set(head, key, key, nullptr);
}
xbt_test_add("Count the elements (retrieving the key and data for each)");
xbt_test_log("There is %d elements", countelems(head));
xbt_test_add("Count the elements (retrieving the key and data for each)");
xbt_test_log("There is %d elements", countelems(head));
xbt_test_add("Search my %d elements 20 times", NB_ELM);
char* key = (char*)xbt_malloc(10);
for (int i = 0; i < 20; i++) {
xbt_test_add("Search my %d elements 20 times", NB_ELM);
char* key = (char*)xbt_malloc(10);
for (int i = 0; i < 20; i++) {
for (int j = 0; j < NB_ELM; j++) {
snprintf(key,10, "%d", j);
void* data = xbt_dict_get(head, key);
for (int j = 0; j < NB_ELM; j++) {
snprintf(key,10, "%d", j);
void* data = xbt_dict_get(head, key);