test/list_tests.c

branch
support/2.x
changeset 471
e9ef2637e101
parent 371
365b24f20f98
equal deleted inserted replaced
388:871a8ffe6c9d 471:e9ef2637e101
402 402
403 ucx_list_free(expected); 403 ucx_list_free(expected);
404 ucx_list_free(list); 404 ucx_list_free(list);
405 } 405 }
406 406
407 UCX_TEST(test_ucx_list_sort_int) {
408 int expected[] = {
409 14, 30, 151, 163, 227, 300, 315, 317, 363, 398, 417, 424, 438, 446, 508, 555, 605, 713, 716, 759, 761, 880,
410 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 1707, 1734, 1771, 1874, 1894,
411 1976, 2079, 2124, 2130, 2135, 2266, 2338, 2358, 2430, 2500, 2540, 2542, 2546, 2711, 2733, 2754, 2764, 2797,
412 2888, 2900, 3020, 3053, 3109, 3244, 3275, 3302, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 3675, 3677,
413 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681,
414 4785, 4791, 4801, 4859, 4903, 4973
415 };
416 int scrambled[] = {
417 759, 716, 880, 761, 2358, 2542, 2500, 2540, 2546, 2711, 2430, 1707, 1874, 1771, 1894, 1734, 1976, 2079,
418 2124, 2130, 2135, 2266, 2338, 2733, 2754, 2764, 2797, 3362, 3363, 3364, 3441, 3515, 3539, 3579, 3655, 2888,
419 2900, 3020, 3053, 3109, 3244, 3275, 3302, 438, 446, 508, 555, 605, 713, 14, 30, 151, 163, 227, 300,
420 894, 1034, 1077, 1191, 1231, 1264, 1297, 1409, 1423, 1511, 1544, 1659, 1686, 315, 317, 363, 398, 417, 424,
421 3675, 3677, 3718, 3724, 3757, 3866, 3896, 3906, 3941, 3984, 3994, 4785, 4791, 4801, 4859, 4903, 4973,
422 4016, 4085, 4121, 4254, 4319, 4366, 4459, 4514, 4681
423 };
424
425 UcxList *list = NULL;
426 for (int i = 0 ; i < 100 ; i++) {
427 list = ucx_list_append(list, scrambled+i);
428 }
429
430 list = ucx_list_sort(list, ucx_cmp_int, NULL);
431
432 UCX_TEST_BEGIN
433
434 UCX_TEST_ASSERT(list->prev == NULL, "prev field of first entry is not null");
435 UcxList *check = list;
436 UcxList *check_last = NULL;
437 for (int i = 0 ; i < 100 ; i++) {
438 UCX_TEST_ASSERT(*(int*)check->data == expected[i], "data not correctly sorted");
439 UCX_TEST_ASSERT(check->prev == check_last, "prev pointer not correct");
440 if (i < 99) {
441 UCX_TEST_ASSERT(check->next != NULL, "next pointer not correct");
442 }
443 check_last = check;
444 check = check->next;
445 }
446 UCX_TEST_ASSERT(check == NULL, "next pointer of last element not null");
447
448 UCX_TEST_END
449
450 ucx_list_free(list);
451 }
452
407 UCX_TEST(test_ucx_list_union) { 453 UCX_TEST(test_ucx_list_union) {
408 UcxList *left = ucx_list_append(NULL, (void*)"this"); 454 UcxList *left = ucx_list_append(NULL, (void*)"this");
409 left = ucx_list_append(left, (void*)"is"); 455 left = ucx_list_append(left, (void*)"is");
410 left = ucx_list_append(left, (void*)"a"); 456 left = ucx_list_append(left, (void*)"a");
411 left = ucx_list_append(left, (void*)"test"); 457 left = ucx_list_append(left, (void*)"test");

mercurial