| 3 */ |
3 */ |
| 4 |
4 |
| 5 #include "dlist_tests.h" |
5 #include "dlist_tests.h" |
| 6 |
6 |
| 7 UCX_TEST_IMPLEMENT(test_ucx_dlist_append) { |
7 UCX_TEST_IMPLEMENT(test_ucx_dlist_append) { |
| 8 UcxDlist *list = ucx_dlist_append(NULL, "Hello"); |
8 UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello"); |
| 9 UCX_TEST_BEGIN |
9 UCX_TEST_BEGIN |
| 10 |
10 |
| 11 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
11 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
| 12 "failed"); |
12 "failed"); |
| 13 |
13 |
| 14 list = ucx_dlist_append(list, " World!"); |
14 list = ucx_dlist_append(list, (void*)" World!"); |
| 15 |
15 |
| 16 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
16 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
| 17 "failed"); |
17 "failed"); |
| 18 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
18 UCX_TEST_ASSERT(list->next->next == NULL, "failed"); |
| 19 UCX_TEST_END |
19 UCX_TEST_END |
| 20 |
20 |
| 21 ucx_dlist_free(list); |
21 ucx_dlist_free(list); |
| 22 } |
22 } |
| 23 |
23 |
| 24 UCX_TEST_IMPLEMENT(test_ucx_dlist_prepend) { |
24 UCX_TEST_IMPLEMENT(test_ucx_dlist_prepend) { |
| 25 UcxDlist *list = ucx_dlist_prepend(NULL, " World!"); |
25 UcxDlist *list = ucx_dlist_prepend(NULL, (void*)" World!"); |
| 26 UCX_TEST_BEGIN |
26 UCX_TEST_BEGIN |
| 27 |
27 |
| 28 list = ucx_dlist_prepend(list, "Hello"); |
28 list = ucx_dlist_prepend(list, (void*)"Hello"); |
| 29 |
29 |
| 30 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
30 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
| 31 "failed"); |
31 "failed"); |
| 32 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
32 UCX_TEST_ASSERT(strncmp((const char*)list->next->data, " World!", 7) == 0, |
| 33 "failed"); |
33 "failed"); |
| 36 UCX_TEST_END |
36 UCX_TEST_END |
| 37 ucx_dlist_free(list); |
37 ucx_dlist_free(list); |
| 38 } |
38 } |
| 39 |
39 |
| 40 UCX_TEST_IMPLEMENT(test_ucx_dlist_equals) { |
40 UCX_TEST_IMPLEMENT(test_ucx_dlist_equals) { |
| 41 UcxDlist *list = ucx_dlist_append(NULL, "Hello"); |
41 UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello"); |
| 42 list = ucx_dlist_append(list, " World!"); |
42 list = ucx_dlist_append(list, (void*)" World!"); |
| 43 UcxDlist *list2 = ucx_dlist_prepend(NULL, " World!"); |
43 UcxDlist *list2 = ucx_dlist_prepend(NULL, (void*)" World!"); |
| 44 list2 = ucx_dlist_prepend(list2, "Hello"); |
44 list2 = ucx_dlist_prepend(list2, (void*)"Hello"); |
| 45 UcxDlist *list3 = ucx_dlist_prepend(NULL, " Welt!"); |
45 UcxDlist *list3 = ucx_dlist_prepend(NULL, (void*)" Welt!"); |
| 46 list3 = ucx_dlist_prepend(list3, "Hallo"); |
46 list3 = ucx_dlist_prepend(list3, (void*)"Hallo"); |
| 47 UCX_TEST_BEGIN |
47 UCX_TEST_BEGIN |
| 48 |
48 |
| 49 UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, cmp_string, NULL), "failed"); |
49 UCX_TEST_ASSERT(ucx_dlist_equals(list, list2, cmp_string, NULL), "failed"); |
| 50 UCX_TEST_ASSERT(!ucx_dlist_equals(list, list3, cmp_string, NULL), "failed"); |
50 UCX_TEST_ASSERT(!ucx_dlist_equals(list, list3, cmp_string, NULL), "failed"); |
| 51 |
51 |
| 71 UCX_TEST_END |
71 UCX_TEST_END |
| 72 ucx_dlist_free(list); |
72 ucx_dlist_free(list); |
| 73 } |
73 } |
| 74 |
74 |
| 75 UCX_TEST_IMPLEMENT(test_ucx_dlist_size) { |
75 UCX_TEST_IMPLEMENT(test_ucx_dlist_size) { |
| 76 UcxDlist *list = ucx_dlist_append(NULL, "This "); |
76 UcxDlist *list = ucx_dlist_append(NULL, (void*)"This "); |
| 77 UCX_TEST_BEGIN |
77 UCX_TEST_BEGIN |
| 78 list = ucx_dlist_append(list, "list "); |
78 list = ucx_dlist_append(list, (void*)"list "); |
| 79 list = ucx_dlist_append(list, "has "); |
79 list = ucx_dlist_append(list, (void*)"has "); |
| 80 list = ucx_dlist_append(list, "size "); |
80 list = ucx_dlist_append(list, (void*)"size "); |
| 81 list = ucx_dlist_append(list, "5!"); |
81 list = ucx_dlist_append(list, (void*)"5!"); |
| 82 |
82 |
| 83 UCX_TEST_ASSERT(ucx_dlist_size(list) == 5, "failed"); |
83 UCX_TEST_ASSERT(ucx_dlist_size(list) == 5, "failed"); |
| 84 |
84 |
| 85 UCX_TEST_END |
85 UCX_TEST_END |
| 86 ucx_dlist_free(list); |
86 ucx_dlist_free(list); |
| 87 } |
87 } |
| 88 |
88 |
| 89 UCX_TEST_IMPLEMENT(test_ucx_dlist_first) { |
89 UCX_TEST_IMPLEMENT(test_ucx_dlist_first) { |
| 90 UcxDlist *list = ucx_dlist_append(NULL, "Find "); |
90 UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find "); |
| 91 UCX_TEST_BEGIN |
91 UCX_TEST_BEGIN |
| 92 list = ucx_dlist_append(list, "the "); |
92 list = ucx_dlist_append(list, (void*)"the "); |
| 93 list = ucx_dlist_append(list, "first!"); |
93 list = ucx_dlist_append(list, (void*)"first!"); |
| 94 |
94 |
| 95 const char* first = (const char*) (ucx_dlist_first(list)->data); |
95 const char* first = (const char*) (ucx_dlist_first(list)->data); |
| 96 |
96 |
| 97 UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed"); |
97 UCX_TEST_ASSERT(strncmp(first, "Find ", 5) == 0, "failed"); |
| 98 |
98 |
| 99 UCX_TEST_END |
99 UCX_TEST_END |
| 100 ucx_dlist_free(list); |
100 ucx_dlist_free(list); |
| 101 } |
101 } |
| 102 |
102 |
| 103 UCX_TEST_IMPLEMENT(test_ucx_dlist_last) { |
103 UCX_TEST_IMPLEMENT(test_ucx_dlist_last) { |
| 104 UcxDlist *list = ucx_dlist_append(NULL, "Find "); |
104 UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find "); |
| 105 UCX_TEST_BEGIN |
105 UCX_TEST_BEGIN |
| 106 list = ucx_dlist_append(list, "the "); |
106 list = ucx_dlist_append(list, (void*)"the "); |
| 107 list = ucx_dlist_append(list, "last!"); |
107 list = ucx_dlist_append(list, (void*)"last!"); |
| 108 |
108 |
| 109 const char* last = (const char*) (ucx_dlist_last(list)->data); |
109 const char* last = (const char*) (ucx_dlist_last(list)->data); |
| 110 |
110 |
| 111 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); |
111 UCX_TEST_ASSERT(strncmp(last, "last!", 5) == 0, "failed"); |
| 112 |
112 |
| 113 UCX_TEST_END |
113 UCX_TEST_END |
| 114 ucx_dlist_free(list); |
114 ucx_dlist_free(list); |
| 115 } |
115 } |
| 116 |
116 |
| 117 UCX_TEST_IMPLEMENT(test_ucx_dlist_get) { |
117 UCX_TEST_IMPLEMENT(test_ucx_dlist_get) { |
| 118 UcxDlist *list = ucx_dlist_append(NULL, "Find "); |
118 UcxDlist *list = ucx_dlist_append(NULL, (void*)"Find "); |
| 119 UCX_TEST_BEGIN |
119 UCX_TEST_BEGIN |
| 120 list = ucx_dlist_append(list, "the "); |
120 list = ucx_dlist_append(list, (void*)"the "); |
| 121 list = ucx_dlist_append(list, "mid!"); |
121 list = ucx_dlist_append(list, (void*)"mid!"); |
| 122 |
122 |
| 123 const char* mid = (const char*) (ucx_dlist_get(list, 1)->data); |
123 const char* mid = (const char*) (ucx_dlist_get(list, 1)->data); |
| 124 |
124 |
| 125 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); |
125 UCX_TEST_ASSERT(strncmp(mid, "the ", 4) == 0, "failed"); |
| 126 |
126 |
| 127 UCX_TEST_END |
127 UCX_TEST_END |
| 128 ucx_dlist_free(list); |
128 ucx_dlist_free(list); |
| 129 } |
129 } |
| 130 |
130 |
| 131 UCX_TEST_IMPLEMENT(test_ucx_dlist_remove) { |
131 UCX_TEST_IMPLEMENT(test_ucx_dlist_remove) { |
| 132 UcxDlist *list = ucx_dlist_append(NULL, "Hello"); |
132 UcxDlist *list = ucx_dlist_append(NULL, (void*)"Hello"); |
| 133 UCX_TEST_BEGIN |
133 UCX_TEST_BEGIN |
| 134 list = ucx_dlist_append(list, " fucking"); |
134 list = ucx_dlist_append(list, (void*)" fucking"); |
| 135 list = ucx_dlist_append(list, " World!"); |
135 list = ucx_dlist_append(list, (void*)" World!"); |
| 136 |
136 |
| 137 list = ucx_dlist_remove(list, ucx_dlist_get(list, 1)); |
137 list = ucx_dlist_remove(list, ucx_dlist_get(list, 1)); |
| 138 |
138 |
| 139 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
139 UCX_TEST_ASSERT(strncmp((const char*)list->data, "Hello", 5) == 0, |
| 140 "failed"); |
140 "failed"); |
| 173 ucx_dlist_free(list); |
173 ucx_dlist_free(list); |
| 174 ucx_dlist_free(copy); |
174 ucx_dlist_free(copy); |
| 175 } |
175 } |
| 176 |
176 |
| 177 UCX_TEST_IMPLEMENT(test_ucx_dlist_sort) { |
177 UCX_TEST_IMPLEMENT(test_ucx_dlist_sort) { |
| 178 UcxDlist *list = ucx_dlist_append(NULL, "this"); |
178 UcxDlist *list = ucx_dlist_append(NULL, (void*)"this"); |
| 179 list = ucx_dlist_append(list, "is"); |
179 list = ucx_dlist_append(list, (void*)"is"); |
| 180 list = ucx_dlist_append(list, "a"); |
180 list = ucx_dlist_append(list, (void*)"a"); |
| 181 list = ucx_dlist_append(list, "test"); |
181 list = ucx_dlist_append(list, (void*)"test"); |
| 182 list = ucx_dlist_append(list, "for"); |
182 list = ucx_dlist_append(list, (void*)"for"); |
| 183 list = ucx_dlist_append(list, "partial"); |
183 list = ucx_dlist_append(list, (void*)"partial"); |
| 184 list = ucx_dlist_append(list, "correctness"); |
184 list = ucx_dlist_append(list, (void*)"correctness"); |
| 185 |
185 |
| 186 UcxDlist *expected = ucx_dlist_append(NULL, "a"); |
186 UcxDlist *expected = ucx_dlist_append(NULL, (void*)"a"); |
| 187 expected = ucx_dlist_append(expected, "correctness"); |
187 expected = ucx_dlist_append(expected, (void*)"correctness"); |
| 188 expected = ucx_dlist_append(expected, "for"); |
188 expected = ucx_dlist_append(expected, (void*)"for"); |
| 189 expected = ucx_dlist_append(expected, "is"); |
189 expected = ucx_dlist_append(expected, (void*)"is"); |
| 190 expected = ucx_dlist_append(expected, "partial"); |
190 expected = ucx_dlist_append(expected, (void*)"partial"); |
| 191 expected = ucx_dlist_append(expected, "test"); |
191 expected = ucx_dlist_append(expected, (void*)"test"); |
| 192 expected = ucx_dlist_append(expected, "this"); |
192 expected = ucx_dlist_append(expected, (void*)"this"); |
| 193 |
193 |
| 194 list = ucx_dlist_sort(list, cmp_string, NULL); |
194 list = ucx_dlist_sort(list, cmp_string, NULL); |
| 195 |
195 |
| 196 UCX_TEST_BEGIN |
196 UCX_TEST_BEGIN |
| 197 UCX_TEST_ASSERT( |
197 UCX_TEST_ASSERT( |