test/test_list.c

changeset 474
9c1fccda16bc
parent 473
1bd4b8c28722
child 475
31bf97fdbf71
equal deleted inserted replaced
473:1bd4b8c28722 474:9c1fccda16bc
395 395
396 cxLinkedListDestroy(list); 396 cxLinkedListDestroy(list);
397 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 397 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
398 } 398 }
399 399
400 void test_hl_linked_list_last(void) {
401 cxTestingAllocatorReset();
402
403 int data;
404 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
405
406 CU_ASSERT_PTR_NULL(cxListLast(list))
407
408 data = 5;
409 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
410 CU_ASSERT_EQUAL(*(int *) cxListLast(list), 5)
411
412 data = 47;
413 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
414 CU_ASSERT_EQUAL(*(int *) cxListLast(list), 47)
415
416 cxLinkedListDestroy(list);
417 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
418 }
419
420 void test_hl_linked_list_insert(void) { 400 void test_hl_linked_list_insert(void) {
421 cxTestingAllocatorReset(); 401 cxTestingAllocatorReset();
422 402
423 int data; 403 int data;
424 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); 404 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
607 587
608 cxLinkedListDestroy(list); 588 cxLinkedListDestroy(list);
609 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 589 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
610 } 590 }
611 591
612 void test_hl_ptr_linked_list_last(void) {
613 cxTestingAllocatorReset();
614
615 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
616 CU_ASSERT_PTR_NULL(cxListLast(list))
617
618 int a = 5, b = 47;
619
620 CU_ASSERT_EQUAL(cxListAdd(list, &a), 0)
621 CU_ASSERT_EQUAL(*(int *) cxListLast(list), 5)
622 CU_ASSERT_EQUAL(cxListAdd(list, &b), 0)
623 CU_ASSERT_EQUAL(*(int *) cxListLast(list), 47)
624
625 cxLinkedListDestroy(list);
626 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
627 }
628
629 void test_hl_ptr_linked_list_insert(void) { 592 void test_hl_ptr_linked_list_insert(void) {
630 cxTestingAllocatorReset(); 593 cxTestingAllocatorReset();
631 594
632 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); 595 CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
633 596
785 748
786 suite = CU_add_suite("high level linked list", NULL, NULL); 749 suite = CU_add_suite("high level linked list", NULL, NULL);
787 750
788 cu_add_test(suite, test_hl_linked_list_create); 751 cu_add_test(suite, test_hl_linked_list_create);
789 cu_add_test(suite, test_hl_linked_list_add); 752 cu_add_test(suite, test_hl_linked_list_add);
790 cu_add_test(suite, test_hl_linked_list_last);
791 cu_add_test(suite, test_hl_linked_list_insert); 753 cu_add_test(suite, test_hl_linked_list_insert);
792 cu_add_test(suite, test_hl_linked_list_remove); 754 cu_add_test(suite, test_hl_linked_list_remove);
793 cu_add_test(suite, test_hl_linked_list_find); 755 cu_add_test(suite, test_hl_linked_list_find);
794 cu_add_test(suite, test_hl_linked_list_sort); 756 cu_add_test(suite, test_hl_linked_list_sort);
795 757
796 suite = CU_add_suite("high level pointer linked list", NULL, NULL); 758 suite = CU_add_suite("high level pointer linked list", NULL, NULL);
797 759
798 cu_add_test(suite, test_hl_ptr_linked_list_create); 760 cu_add_test(suite, test_hl_ptr_linked_list_create);
799 cu_add_test(suite, test_hl_ptr_linked_list_add); 761 cu_add_test(suite, test_hl_ptr_linked_list_add);
800 cu_add_test(suite, test_hl_ptr_linked_list_last);
801 cu_add_test(suite, test_hl_ptr_linked_list_insert); 762 cu_add_test(suite, test_hl_ptr_linked_list_insert);
802 cu_add_test(suite, test_hl_ptr_linked_list_remove); 763 cu_add_test(suite, test_hl_ptr_linked_list_remove);
803 cu_add_test(suite, test_hl_ptr_linked_list_find); 764 cu_add_test(suite, test_hl_ptr_linked_list_find);
804 cu_add_test(suite, test_hl_ptr_linked_list_sort); 765 cu_add_test(suite, test_hl_ptr_linked_list_sort);
805 766

mercurial