TEST(removeTest, Positive03){ Solution s; int A[] = {1, 4, 3, 2, 0, 2, -1}; const int n1 = sizeof(A) / sizeof(int); ListNode *l1 = createSLL(A, n1); int x = 3; ListNode* result = s.partition(l1, x); int B[] = {1, 2, 0, 2, -1, 4, 3}; const int n2 = sizeof(B) / sizeof(int); ListNode *expected = createSLL(B, n2); assertList(expected, result); delSLL(expected); delSLL(result); }
/* ------------------ test body ---------------- */ TEST(mergeSortedListTest, Positive01){ Solution s; int A[] = {1, 4, 5, 6, 8, 12, 15, 16}; int B[] = {2, 3, 7, 9, 10, 11, 13, 14, 17, 20}; const int n1 = sizeof(A)/sizeof(int); const int n2 = sizeof(B)/sizeof(int); ListNode *l1 = createSLL(A, n1); ListNode *l2 = createSLL(B, n2); ListNode* result = s.mergeList(l1, l2); vector<int> expectedVector; // values of expected list for(int i = 0; i < n1; i++){ expectedVector.push_back(A[i]); } for(int i = 0; i < n2; i++){ expectedVector.push_back(B[i]); } sort(expectedVector.begin(), expectedVector.end()); // <algorithm>, std::sort() ListNode *expected = new ListNode(expectedVector[0]); ListNode *h = expected; for(int i = 1; i < n1 + n2; i++){ h->next = new ListNode(expectedVector[i]); h = h->next; } assertList(expected, result); expectedVector.clear(); delSLL(expected); delSLL(result); }
void test_01(){ string str; while(1){ printf("please input integer array of List:\n"); if(getline(cin, str)==0 || str.empty()) break; int *arr = new int[str.size()](); int n = splitStr2IntArray(str, arr); ListNode *head = generateList(arr, n); delete[] arr; arr = 0; printf("input k offset to rotate right:\n"); if(getline(cin, str)==0 || str.empty()) continue; int k = atoi(str.c_str()); ListNode *h = rotateRight(head, k); displaySLL(h); delSLL(h); } return; }