void test_slist_prepend_to_empty(void) { unsigned long *val = NULL; assert_true(test_slist == NULL); test_slist = slist_create(); assert_true(test_slist != NULL); assert_true(slist_is_empty(test_slist)); val = make_ulong_ptr(9999); assert_true(val != NULL); assert_true(slist_prepend(test_slist, val) == 0); /* Verify */ val = NULL; val = slist_index(test_slist, 0); assert_true(val != NULL); assert_ulong_equal(9999, *val); assert_true(slist_size(test_slist) == 1); slist_free_all(test_slist, NULL); test_slist = NULL; }
END_TEST /* Testeo de funcionalidad */ START_TEST(test_network_get_edges) { Edge *e1 = NULL, *e2 = NULL, *e3 = NULL, *etmp = NULL; SList *el = NULL, *tmp = NULL; Node ntmp = 0; e1 = edge_create(0, 1, 1, 0); e2 = edge_create(0, 2, 1, 0); e3 = edge_create(2, 3, 1, 0); net = network_create(); network_add_edge(net, e1); network_add_edge(net, e2); network_add_edge(net, e3); el = network_get_edges(net, 0); fail_unless(!slist_is_empty(el)); tmp = el; while(tmp != NULL){ etmp = (Edge *) slist_nth_data(tmp, 0); ntmp = *edge_get_second(etmp); fail_unless(ntmp == 1 || ntmp == 2); tmp = slist_next(tmp); } network_destroy(net); }
END_TEST START_TEST(test_network_get_neightbours) { Edge *e1 = NULL, *e2 = NULL, *e3 = NULL; Node *ntmp = NULL; SList *el = NULL, *tmp = NULL; e1 = edge_create(2, 3, 1, 0); e2 = edge_create(1, 4, 1, 0); e3 = edge_create(2, 1, 1, 0); net = network_create(); network_add_edge(net, e1); network_add_edge(net, e2); network_add_edge(net, e3); el = network_neighbours(net, 2); fail_unless(!slist_is_empty(el)); tmp = el; while(tmp != NULL){ ntmp = (Node *) slist_nth_data(tmp, 0); fail_unless(*ntmp == 3 || *ntmp == 1); tmp = slist_next(tmp); } slist_free(el); network_destroy(net); }
static void test_empty(void) { struct list_node *spos, *ssafe; struct node *pos, *safe; check(!slist_is_empty(&slist), "slist is empty but slist_is_empty returned false"); check(!list_is_empty(&list), "list is empty but list_is_empty returned false"); check(slist_head(&slist) != &slist, "slist is empty but slist_head returned non-self"); check(list_head(&list) != NULL, "list is empty but list_head returned non-NULL"); check(slist_tail(&slist) != &slist, "slist is empty but slist_tail returned non-self"); check(list_tail(&list) != NULL, "list is empty but list_tail returned non-NULL"); check_loop_never(slist_for_each(spos, &slist), "slist is empty, but slist_for_each looped"); check_loop_never(list_for_each(pos, &list), "list is empty, but list_for_each looped"); check_loop_never(slist_for_each_safe(spos, ssafe, &slist), "slist is empty, but slist_for_each_safe looped"); check_loop_never(list_for_each_safe(pos, safe, &list), "list is empty, but list_for_each_safe looped"); check_loop_never(slist_for_each_entry(pos, &slist, node), "slist is empty, but slist_for_each_entry looped"); check_loop_never(slist_for_each_entry_safe(pos, safe, &slist, node), "slist is empty, but slist_for_each-entry_safe looped"); }
TESTS_BEGIN /* * 1. Basic: * SLIST_AUTO( name ) * void slist_init( SList list ) * int slist_is_empty( const_SList list ) * int slist_is_single( const_SList list ) * int slist_is_head( const_SList list, const_SList head ) * int slist_is_end( const_SList list, const_SList end ) * int slist_is_member( const_SList list, const_SList member ) * int slist_is_before_after( const_SList list, const_SList before, const_SList after ) */ TEST (basic) { SLIST_AUTO( listX ); slist listY; SLIST_AUTO( nodeA ); SLIST_AUTO( nodeB ); ECHO ("%d", slist_is_end( &listX, &listX ) ); slist_init( &listY ); ECHO ("%d", slist_is_empty( &listY ) ); slist_insert( &listX, &nodeA ); ECHO ("%d", slist_is_empty( &listX ) ); ECHO ("%d", slist_is_single( &listX ) ); ECHO ("%d", slist_is_head( &listX, &nodeA ) ); ECHO ("%d", slist_is_end( &listX, &nodeA ) ); ECHO ("%d", slist_is_member( &listX, &nodeA ) ); ECHO ("%d", slist_is_member( &listX, &nodeB ) ); slist_insert( &nodeA, &nodeB ); ECHO ("%d", slist_is_empty( &listX ) ); ECHO ("%d", slist_is_single( &listX ) ); ECHO ("%d", slist_is_head( &listX, &nodeB ) ); ECHO ("%d", slist_is_end( &listX, &nodeB ) ); ECHO ("%d", slist_is_member( &listX, &nodeB ) ); ECHO ("%d", slist_is_before_after( &listX, &nodeA, &nodeB ) ); ECHO ("%d", slist_is_before_after( &listX, &nodeB, &nodeA ) ); }
/* Complexity: O(1) */ void* queue_back(Queue *queue) { assert(queue != NULL); if(slist_is_empty((SList *)queue)) { return NULL; } return slist_index((SList *)queue, slist_size((SList *)queue) - 1); }
void test_slist_create(void) { test_slist = slist_create(); assert_true(test_slist != NULL); assert_true(slist_size(test_slist) == 0); assert_true(slist_is_empty(test_slist)); slist_free(test_slist); test_slist = NULL; }
static int mod_enqueue_nolock(struct ioq *q, struct ioq_fd *f) { int need_wakeup = 0; if (!(f->flags & IOQ_FLAG_MOD_LIST)) { need_wakeup = slist_is_empty(&q->mod_list); f->flags |= IOQ_FLAG_MOD_LIST; slist_append(&q->mod_list, &f->mod_list); } return need_wakeup; }
void test_slist_reverse_empty(void) { assert_true(test_slist == NULL); test_slist = slist_create(); assert_true(test_slist != NULL); assert_true(slist_is_empty(test_slist)); assert_true(slist_reverse(test_slist) == 0); slist_free_all(test_slist, NULL); test_slist = NULL; }
void test_slist_remove_data_from_empty(void) { assert_true(test_slist == NULL); test_slist = slist_create(); assert_true(test_slist != NULL); assert_true(slist_is_empty(test_slist)); assert_true(slist_remove_data(test_slist, NULL) == -1); slist_free_all(test_slist, NULL); test_slist = NULL; }
void slist_setup_ints(void) { unsigned long i, *val; test_slist = slist_create(); assert_true(test_slist != NULL); assert_true(slist_is_empty(test_slist)); for(i = 0; i < 1000; i++) { val = make_ulong_ptr(i); if(val != NULL) { slist_append(test_slist, val); } } }
void test_slist_remove_data_from_existing_until_empty(void) { unsigned long *val; unsigned long i; val = NULL; i = slist_size(test_slist); while(i > 0) { val = slist_index(test_slist, --i); assert_true(val != NULL); assert_true(slist_remove_data(test_slist, val) == 0); assert_true(i == slist_size(test_slist)); } assert_true(slist_is_empty(test_slist)); }
/* Complexity: O(1) */ int queue_is_empty(Queue *queue) { assert(queue != NULL); return slist_is_empty((SList *)queue); }