test/test_list.c

changeset 460
e075009b33b7
parent 459
c0e2e9f83399
child 466
28bc3e10ac28
equal deleted inserted replaced
459:c0e2e9f83399 460:e075009b33b7
179 179
180 int data; 180 int data;
181 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); 181 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
182 182
183 data = 5; 183 data = 5;
184 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) 184 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
185 data = 47; 185 data = 47;
186 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) 186 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
187 data = 13; 187 data = 13;
188 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) 188 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
189 189
190 CU_ASSERT_EQUAL(list->size, 3) 190 CU_ASSERT_EQUAL(list->size, 3)
191 CU_ASSERT_TRUE(list->capacity >= list->size) 191 CU_ASSERT_TRUE(list->capacity >= list->size)
192 192
193 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 5) 193 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5)
194 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 47) 194 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47)
195 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 13) 195 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13)
196 196
197 cxLinkedListDestroy(list); 197 cxLinkedListDestroy(list);
198 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 198 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
199 } 199 }
200 200
202 cxTestingAllocatorReset(); 202 cxTestingAllocatorReset();
203 203
204 int data; 204 int data;
205 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); 205 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
206 206
207 CU_ASSERT_PTR_NULL(cxTypedListLast(int, list)) 207 CU_ASSERT_PTR_NULL(cxListLast(list))
208 208
209 data = 5; 209 data = 5;
210 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) 210 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
211 CU_ASSERT_EQUAL(*cxTypedListLast(int, list), 5) 211 CU_ASSERT_EQUAL(*(int*)cxListLast(list), 5)
212 212
213 data = 47; 213 data = 47;
214 CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) 214 CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
215 CU_ASSERT_EQUAL(*cxTypedListLast(int, list), 47) 215 CU_ASSERT_EQUAL(*(int*)cxListLast(list), 47)
216 216
217 cxLinkedListDestroy(list); 217 cxLinkedListDestroy(list);
218 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 218 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
219 } 219 }
220 220
223 223
224 int data; 224 int data;
225 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); 225 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
226 226
227 data = 5; 227 data = 5;
228 CU_ASSERT_NOT_EQUAL(cxTypedListInsert(int, list, 1, &data), 0) 228 CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &data), 0)
229 CU_ASSERT_EQUAL(list->size, 0) 229 CU_ASSERT_EQUAL(list->size, 0)
230 CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 0, &data), 0) 230 CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0)
231 CU_ASSERT_EQUAL(list->size, 1) 231 CU_ASSERT_EQUAL(list->size, 1)
232 data = 47; 232 data = 47;
233 CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 0, &data), 0) 233 CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0)
234 CU_ASSERT_EQUAL(list->size, 2) 234 CU_ASSERT_EQUAL(list->size, 2)
235 data = 13; 235 data = 13;
236 CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 1, &data), 0) 236 CU_ASSERT_EQUAL(cxListInsert(list, 1, &data), 0)
237 CU_ASSERT_EQUAL(list->size, 3) 237 CU_ASSERT_EQUAL(list->size, 3)
238 data = 42; 238 data = 42;
239 CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 3, &data), 0) 239 CU_ASSERT_EQUAL(cxListInsert(list, 3, &data), 0)
240 240
241 CU_ASSERT_EQUAL(list->size, 4) 241 CU_ASSERT_EQUAL(list->size, 4)
242 CU_ASSERT_TRUE(list->capacity >= list->size) 242 CU_ASSERT_TRUE(list->capacity >= list->size)
243 243
244 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) 244 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 47)
245 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 13) 245 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 13)
246 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 5) 246 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 5)
247 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 3), 42) 247 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 3), 42)
248 248
249 cxLinkedListDestroy(list); 249 cxLinkedListDestroy(list);
250 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 250 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
251 } 251 }
252 252
255 255
256 int data; 256 int data;
257 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); 257 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
258 258
259 data = 5; 259 data = 5;
260 cxTypedListAdd(int, list, &data); 260 cxListAdd(list, &data);
261 data = 47; 261 data = 47;
262 cxTypedListAdd(int, list, &data); 262 cxListAdd(list, &data);
263 data = 42; 263 data = 42;
264 cxTypedListAdd(int, list, &data); 264 cxListAdd(list, &data);
265 data = 13; 265 data = 13;
266 cxTypedListAdd(int, list, &data); 266 cxListAdd(list, &data);
267 267
268 CU_ASSERT_EQUAL(list->size, 4) 268 CU_ASSERT_EQUAL(list->size, 4)
269 CU_ASSERT_TRUE(list->capacity >= list->size) 269 CU_ASSERT_TRUE(list->capacity >= list->size)
270 270
271 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0) 271 CU_ASSERT_NOT_EQUAL(cxListRemove(list, 4), 0)
272 272
273 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) 273 CU_ASSERT_EQUAL(cxListRemove(list, 2), 0)
274 CU_ASSERT_EQUAL(list->size, 3) 274 CU_ASSERT_EQUAL(list->size, 3)
275 CU_ASSERT_TRUE(list->capacity >= list->size) 275 CU_ASSERT_TRUE(list->capacity >= list->size)
276 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 5) 276 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5)
277 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 47) 277 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47)
278 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 13) 278 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13)
279 279
280 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) 280 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
281 CU_ASSERT_EQUAL(list->size, 2) 281 CU_ASSERT_EQUAL(list->size, 2)
282 CU_ASSERT_TRUE(list->capacity >= list->size) 282 CU_ASSERT_TRUE(list->capacity >= list->size)
283 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) 283 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 47)
284 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 13) 284 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 13)
285 285
286 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) 286 CU_ASSERT_EQUAL(cxListRemove(list, 1), 0)
287 CU_ASSERT_EQUAL(list->size, 1) 287 CU_ASSERT_EQUAL(list->size, 1)
288 CU_ASSERT_TRUE(list->capacity >= list->size) 288 CU_ASSERT_TRUE(list->capacity >= list->size)
289 CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) 289 CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 47)
290 290
291 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) 291 CU_ASSERT_EQUAL(cxListRemove(list, 0), 0)
292 CU_ASSERT_EQUAL(list->size, 0) 292 CU_ASSERT_EQUAL(list->size, 0)
293 CU_ASSERT_TRUE(list->capacity >= list->size) 293 CU_ASSERT_TRUE(list->capacity >= list->size)
294 294
303 303
304 int data, criteria; 304 int data, criteria;
305 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); 305 CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
306 306
307 data = 5; 307 data = 5;
308 cxTypedListAdd(int, list, &data); 308 cxListAdd(list, &data);
309 data = 47; 309 data = 47;
310 cxTypedListAdd(int, list, &data); 310 cxListAdd(list, &data);
311 data = 13; 311 data = 13;
312 cxTypedListAdd(int, list, &data); 312 cxListAdd(list, &data);
313 313
314 CU_ASSERT_EQUAL(list->size, 3) 314 CU_ASSERT_EQUAL(list->size, 3)
315 CU_ASSERT_TRUE(list->capacity >= list->size) 315 CU_ASSERT_TRUE(list->capacity >= list->size)
316 316
317 criteria = 5; 317 criteria = 5;
318 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 0) 318 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0)
319 criteria = 47; 319 criteria = 47;
320 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 1) 320 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1)
321 criteria = 13; 321 criteria = 13;
322 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 2) 322 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2)
323 criteria = 9000; 323 criteria = 9000;
324 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 3) 324 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
325 criteria = -5; 325 criteria = -5;
326 CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 3) 326 CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3)
327 327
328 cxLinkedListDestroy(list); 328 cxLinkedListDestroy(list);
329 CU_ASSERT_TRUE(cxTestingAllocatorVerify()) 329 CU_ASSERT_TRUE(cxTestingAllocatorVerify())
330 } 330 }
331 331

mercurial