tests/test_list.c

changeset 831
7970eac1c598
parent 819
5da2ead43077
child 832
97df2e4c68fb
equal deleted inserted replaced
830:c4dae6fe6d5b 831:7970eac1c598
39 CX_TEST(test_array_add) { 39 CX_TEST(test_array_add) {
40 int stackspace[5] = {1,1,2,3,5}; 40 int stackspace[5] = {1,1,2,3,5};
41 int *stackarray = stackspace; 41 int *stackarray = stackspace;
42 size_t stackarray_size = 3; 42 size_t stackarray_size = 3;
43 size_t stackarray_capacity = 5; 43 size_t stackarray_capacity = 5;
44 int *heaparray = calloc(5, sizeof(int)); 44 cx_array_declare(int, heaparray);
45 heaparray = calloc(5, sizeof(int));
45 heaparray[0] = 2; 46 heaparray[0] = 2;
46 heaparray[1] = 3; 47 heaparray[1] = 3;
47 heaparray[2] = 5; 48 heaparray[2] = 5;
48 heaparray[3] = 7; 49 heaparray[3] = 7;
49 heaparray[4] = 11; 50 heaparray[4] = 11;
50 size_t heaparray_size = 3; 51 heaparray_size = 3;
51 size_t heaparray_capacity = 5; 52 heaparray_capacity = 5;
52 int elem = 8, elem2 = 47; 53 int elem = 8, elem2 = 47;
53 enum cx_array_result result; 54 enum cx_array_result result;
54 CX_TEST_DO { 55 CX_TEST_DO {
55 result = cx_array_add(&stackarray, &stackarray_size, &stackarray_capacity, sizeof(int), &elem, NULL); 56 result = cx_array_add(&stackarray, &stackarray_size, &stackarray_capacity, sizeof(int), &elem, NULL);
56 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS); 57 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS);
71 CX_TEST_ASSERT(stackarray[3] == 8); 72 CX_TEST_ASSERT(stackarray[3] == 8);
72 CX_TEST_ASSERT(stackarray[4] == 5); 73 CX_TEST_ASSERT(stackarray[4] == 5);
73 CX_TEST_ASSERT(stackarray_size == 5); 74 CX_TEST_ASSERT(stackarray_size == 5);
74 CX_TEST_ASSERT(stackarray_capacity == 5); 75 CX_TEST_ASSERT(stackarray_capacity == 5);
75 76
76 result = cx_array_add(&heaparray, &heaparray_size, &heaparray_capacity, sizeof(int), &elem, cx_array_default_reallocator); 77 result = cx_array_simple_add(heaparray, &elem);
77 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS); 78 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS);
78 CX_TEST_ASSERT(heaparray[0] == 2); 79 CX_TEST_ASSERT(heaparray[0] == 2);
79 CX_TEST_ASSERT(heaparray[1] == 3); 80 CX_TEST_ASSERT(heaparray[1] == 3);
80 CX_TEST_ASSERT(heaparray[2] == 5); 81 CX_TEST_ASSERT(heaparray[2] == 5);
81 CX_TEST_ASSERT(heaparray[3] == 8); 82 CX_TEST_ASSERT(heaparray[3] == 8);
82 CX_TEST_ASSERT(heaparray[4] == 11); 83 CX_TEST_ASSERT(heaparray[4] == 11);
83 CX_TEST_ASSERT(heaparray_size == 4); 84 CX_TEST_ASSERT(heaparray_size == 4);
84 CX_TEST_ASSERT(heaparray_capacity == 5); 85 CX_TEST_ASSERT(heaparray_capacity == 5);
85 86
86 heaparray_size = 5; 87 heaparray_size = 5;
87 result = cx_array_add(&heaparray, &heaparray_size, &heaparray_capacity, sizeof(int), &elem2, cx_array_default_reallocator); 88 result = cx_array_simple_add(heaparray, &elem2);
88 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS); 89 CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS);
89 CX_TEST_ASSERT(heaparray[0] == 2); 90 CX_TEST_ASSERT(heaparray[0] == 2);
90 CX_TEST_ASSERT(heaparray[1] == 3); 91 CX_TEST_ASSERT(heaparray[1] == 3);
91 CX_TEST_ASSERT(heaparray[2] == 5); 92 CX_TEST_ASSERT(heaparray[2] == 5);
92 CX_TEST_ASSERT(heaparray[3] == 8); 93 CX_TEST_ASSERT(heaparray[3] == 8);

mercurial