int init_user_list( struct linked_list **curr ) { char directory_name[NAME_LEN]; struct linked_list *head = NULL; struct linked_list *activity_list; if (list_fs_elements(CONF_DATASET_DIRECTORY, DT_DIR, &activity_list)) return EXIT_FAILURE; while (activity_list) { struct linked_list *subdir_list; snprintf(directory_name, NAME_LEN, "%s/%s", CONF_DATASET_DIRECTORY, activity_list->name); if (list_fs_elements(directory_name, DT_DIR, &subdir_list)) return EXIT_FAILURE; while (subdir_list) { if (linked_list_contains(head, subdir_list->name) == -1) linked_list_push(&head, subdir_list->name); subdir_list = subdir_list->next; } linked_list_free(subdir_list); activity_list = activity_list->next; } linked_list_free(activity_list); *curr = head; return EXIT_SUCCESS; }
/* * Tests */ int linked_list_test(){ /** * Entry point for tests */ printf("Linked List Tests:\n\n"); int array[] = {1, 2, 3, 4, 42, 11, 6845}; LinkedList *list = create_linked_list_from_array(sizeof(int), array, 7); print_linked_list(list); int testval1 = 42; int testval2 = 47; printf("%d\n", linked_list_contains(list, &testval1)); printf("%d\n", linked_list_contains(list, &testval2)); delete_linked_list(list); return 0; }
void test_lookup() { // get linked_list* ll = linked_list_new(); int i; for (i = 0; i < 100; i++) { linked_list_insert(ll, i * 2); } assert_equals(linked_list_get(ll, 0), 0); assert_equals(linked_list_get(ll, 99), 99 * 2); assert_equals(linked_list_get(ll, 50), 50 * 2); // contains assert_true(linked_list_contains(ll, 10)); assert_false(linked_list_contains(ll, 1)); // peek //assert_equals(linked_list_first(ll), 0); // last //assert_equals(linked_list_last(ll), 99 * 2); // index of }
void test_insert() { // regular insert linked_list* ll = linked_list_new(); linked_list_insert(ll, 2); linked_list_insert(ll, 4); linked_list_insert(ll, 6); assert_equals(linked_list_size(ll), 3); assert_true(linked_list_contains(ll, 2)); assert_true(linked_list_contains(ll, 4)); assert_true(linked_list_contains(ll, 6)); assert_false(linked_list_contains(ll, -1)); assert_false(linked_list_contains(ll, 0)); linked_list_clear(ll); linked_list* ll = linked_list_new(); assert_equals(linked_list_size(ll), 0); assert_false(linked_list_contains(ll, 1)); linked_list_insert(ll, 1); assert_equals(linked_list_size(ll), 1); assert_true(linked_list_contains(ll, 1)); linked_list_clear(ll); // insert by index // set by index }
static char* contains_false(void) { Object* object = create_object(1); mu_assert(false == linked_list_contains(root, object), "Found object that it should not."); return 0; }
static char* contains_true(void) { Object* object = create_object(1); linked_list_append(root, object); mu_assert(true == linked_list_contains(root, object), "Could not find object."); return 0; }