daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Aug 12th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool testListInsertBeforeCurrent() {
  2.  
  3.     int elem1 = 5;
  4.     int elem2 = -3;
  5.     int elem3 = 4;
  6.     int elem4 = 8;
  7.     int elem5 = -2;
  8.  
  9.     List list = listCreate(copyInt, freeInt);
  10.  
  11.     ASSERT_TEST(listInsertBeforeCurrent(NULL,NULL) == LIST_NULL_ARGUMENT);
  12.     ASSERT_TEST(listInsertBeforeCurrent(NULL,&elem1) == LIST_NULL_ARGUMENT);
  13.     ASSERT_TEST(listInsertBeforeCurrent(list,NULL) == LIST_NULL_ARGUMENT);
  14.  
  15.     listInsertLast(list, &elem1);
  16.     listInsertLast(list, &elem2);
  17.     listInsertLast(list, &elem3);
  18.     listInsertLast(list, &elem4);
  19.  
  20.     listGetFirst(list);
  21.     listGetNext(list);
  22.     listGetNext(list);
  23.  
  24.     ASSERT_TEST(listInsertBeforeCurrent(list,&elem5) == LIST_SUCCESS);
  25.  
  26.     ASSERT_TEST(*(int*)listGetFirst(list) == 5);
  27.     ASSERT_TEST(*(int*)listGetNext(list) == -3);
  28.     ASSERT_TEST(*(int*)listGetNext(list) == -2);
  29.     ASSERT_TEST(*(int*)listGetNext(list) == 4);
  30.     ASSERT_TEST(*(int*)listGetNext(list) == 8);
  31.     ASSERT_TEST(listGetNext(list) == NULL);
  32.     ASSERT_TEST(listGetSize(list) == 5);
  33.  
  34.     listGetFirst(list);
  35.     ASSERT_TEST(listInsertBeforeCurrent(list,&elem4) == LIST_SUCCESS);
  36.  
  37.     ASSERT_TEST(*(int*)listGetFirst(list) == 8);
  38.     ASSERT_TEST(*(int*)listGetNext(list) == 5);
  39.     ASSERT_TEST(*(int*)listGetNext(list) == -3);
  40.     ASSERT_TEST(*(int*)listGetNext(list) == -2);
  41.     ASSERT_TEST(*(int*)listGetNext(list) == 4);
  42.     ASSERT_TEST(*(int*)listGetNext(list) == 8);
  43.     ASSERT_TEST(listGetNext(list) == NULL);
  44.     ASSERT_TEST(listGetSize(list) == 6);
  45.  
  46.     listDestroy(list);
  47.  
  48.     list = listCreate(copyInt, freeInt);
  49.     ASSERT_TEST(listInsertBeforeCurrent(list,&elem1) == LIST_INVALID_CURRENT);
  50.  
  51.     listDestroy(list);
  52.  
  53.     return true;
  54. }
RAW Paste Data
Top