void test_queue3(queue_t q, queue_pfcompare_t pf){ queue_append(q, &c); queue_append(q, &c); queue_append(q, &c); queue_reverse(q); queue_sort(q, pf); queue_link_t cur = q->head; int k = 0; while(k < 3){ if(*(int*)cur->e != 2){ puts("test_queue3 failed @ line 227"); } k++; cur = cur->next; } queue_element_t e = NULL; queue_remove(q, &e); queue_remove(q, &e); queue_remove(q, &e); if(queue_size(q) != 0) puts("test_queue3 failed @ line 238"); if(q->head != NULL) puts("test_queue3 failes @ line 240"); }
void test_queue5(queue_t q, queue_pfcompare_t pf){ queue_append(q, &a); queue_reverse(q); queue_sort(q, pf); queue_element_t e = NULL; queue_remove(q, &e); if(queue_size(q) != 0) puts("test_queue5 failed @ line 289"); if(q->head != NULL) puts("test_queue5 failes @ line 291"); }
void test_reverse(int* errors) { char* location = "test_remove"; queue* q = queue_create(); confirm_size(q, 0, location, errors); queue_reverse(q); queue_element* expected0[] = {}; confirm_order(q, expected0, location, errors); int x = 0; int y = 1; int z = 2; confirm_append(q, &x, 1, location, errors); queue_reverse(q); queue_element* expected1[] = {&x}; confirm_order(q, expected1, location, errors); confirm_append(q, &y, 2, location, errors); queue_reverse(q); queue_element* expected2[] = {&y, &x}; confirm_order(q, expected2, location, errors); confirm_append(q, &z, 3, location, errors); queue_reverse(q); queue_element* expected3[] = {&z, &x, &y}; confirm_order(q, expected3, location, errors); confirm_append(q, &x, 4, location, errors); queue_reverse(q); queue_element* expected4[] = {&x, &y, &x, &z}; confirm_order(q, expected4, location, errors); queue_destroy(q); q = NULL; }
int reverse_test(){ queue* q = queue_create(); int x = 0; int y = 1; int z = 2; queue_append(q, &x); queue_append(q, &y); queue_append(q, &z); assert(queue_size(q) == 3); int *ret_val; queue_reverse(q); queue_remove(q, (queue_element **)&ret_val); assert(*ret_val == z); queue_remove(q, (queue_element **)&ret_val); assert(*ret_val == y); queue_remove(q, (queue_element **)&ret_val); assert(*ret_val == x); queue_destroy(q,false); return 0; }
void test_queue4(queue_t q, queue_pfcompare_t pf){ queue_append(q, &b); queue_append(q, &c); queue_append(q, &d); queue_append(q, &a); queue_reverse(q); queue_link_t cur = q->head; int k = 0; while(k < 4){ if(k == 0 && *(int*)cur->e != 0) puts("test_queue3 failed @ line 252"); if(k == 1 && *(int*)cur->e != -4) puts("test_queue3 failed @ line 253"); if(k == 2 && *(int*)cur->e != 2) puts("test_queue3 failed @ line 254"); if(k == 3 && *(int*)cur->e != 1) puts("test_queue3 failed @ line 255"); k++; cur = cur->next; } cur = q->head; queue_sort(q, pf); k = 0; while(k < 4){ if(k == 0 && *(int*)cur->e != -4) puts("test_queue2 failed @ line 263"); if(k == 1 && *(int*)cur->e != 0) puts("test_queue2 failed @ line 264"); if(k == 2 && *(int*)cur->e != 1) puts("test_queue2 failed @ line 265"); if(k == 3 && *(int*)cur->e != 2) puts("test_queue2 failed @ line 266"); k++; cur = cur->next; } queue_element_t e = NULL; queue_remove(q, &e); queue_remove(q, &e); queue_remove(q, &e); queue_remove(q, &e); if(queue_size(q) != 0) puts("test_queue4 failed @ line 277"); if(q->head != NULL) puts("test_queue4 failes @ line 279"); }