📄 doublelinkedlistdiagnose.h
字号:
} if (list_ptr_2->getFirst()->ne(*items[4]) || (list_ptr_2->length() != 20)) { return Error::handle(name(), L"insertFirst(list)", Error::TEST, __FILE__, __LINE__); } // go to the marked node position // list_ptr_0->gotoMark(); list_ptr_2->gotoMark(); if (list_ptr_0->getPrev()->ne(*items[3])) { return Error::handle(name(), L"insertFirst(list)", Error::TEST, __FILE__, __LINE__); } if (list_ptr_2->getPrev()->ne(*items[3])) { return Error::handle(name(), L"insertFirst(list)", Error::TEST, __FILE__, __LINE__); } // insert a list into the middle of another list // list_ptr_0->insert(*list_ptr_1); // 401230 40123 11030130124012 list_ptr_2->insert(*list_ptr_1); // 401230 40123 11030130124012 if ((list_ptr_0->getCurr()->ne(*items[3])) || (list_ptr_0->length() != 25)) { return Error::handle(name(), L"insert(list)", Error::TEST, __FILE__, __LINE__); } if ((list_ptr_2->getCurr()->ne(*items[3])) || (list_ptr_2->length() != 25)) { return Error::handle(name(), L"insert(list)", Error::TEST, __FILE__, __LINE__); } if (list_ptr_0->getNext()->ne(*items[1])) { return Error::handle(name(), L"insert(list)", Error::TEST, __FILE__, __LINE__); } if (list_ptr_2->getNext()->ne(*items[1])) { return Error::handle(name(), L"insert(list)", Error::TEST, __FILE__, __LINE__); } // insert a list into the end of another list // list_ptr_0->insertLast(*list_ptr_1); // 4012304012311030130124012 40123 list_ptr_2->insertLast(*list_ptr_1); // 4012304012311030130124012 40123 if ((list_ptr_0->getLast()->ne(*items[3])) || (list_ptr_0->length() != 30)) { return Error::handle(name(), L"insertLast(list)", Error::TEST, __FILE__, __LINE__); } if ((list_ptr_2->getLast()->ne(*items[3])) || (list_ptr_2->length() != 30)) { return Error::handle(name(), L"insertLast(list)", Error::TEST, __FILE__, __LINE__); } if (list_ptr_0->curr_d != list_ptr_0->last_d) { return Error::handle(name(), L"insertLast(list)", Error::TEST, __FILE__, __LINE__); } if (list_ptr_2->curr_d != list_ptr_2->last_d) { return Error::handle(name(), L"insertLast(list)", Error::TEST, __FILE__, __LINE__); } // test removeFirst // Char* tmp_item = (Char*)NULL; // the pointer to the removed item list_ptr_0->gotoFirst(); list_ptr_0->removeFirst(tmp_item); // 01230401231103013012401240123 if ((list_ptr_0->first_d != list_ptr_0->curr_d) || (list_ptr_0->first_d->getItem()->ne(*items[0]))) { return Error::handle(name(), L"removeFirst", Error::TEST, __FILE__, __LINE__); } if ((tmp_item->ne(*items[4])) || (list_ptr_0->length() != 29)) { return Error::handle(name(), L"removeFirst", Error::TEST, __FILE__, __LINE__); } list_ptr_2->gotoFirst(); list_ptr_2->removeFirst(); // 01230401231103013012401240123 if ((list_ptr_2->first_d != list_ptr_2->curr_d) || (list_ptr_2->length() != 29) || (list_ptr_2->first_d->getItem()->ne(*items[0]))) { return Error::handle(name(), L"removeFirst", Error::TEST, __FILE__, __LINE__); } // test remove when the current pointer is at the first position // list_ptr_0->gotoFirst(); list_ptr_0->remove(tmp_item); // 1230401231103013012401240123 if (list_ptr_0->curr_d != list_ptr_0->first_d || (list_ptr_0->curr_d->getItem()->ne(*items[1]))) { return Error::handle(name(), L"remove", Error::TEST, __FILE__, __LINE__); } if ((tmp_item->ne(*items[0])) || (list_ptr_0->length() != 28)) { return Error::handle(name(), L"remove (first)", Error::TEST, __FILE__, __LINE__); } list_ptr_2->gotoFirst(); list_ptr_2->remove(); // 1230401231103013012401240123 if (list_ptr_2->curr_d != list_ptr_2->first_d || (list_ptr_2->length() != 28) || (list_ptr_2->curr_d->getItem()->ne(*items[1]))) { return Error::handle(name(), L"remove", Error::TEST, __FILE__, __LINE__); } // move the current node pointer to somewhere inside the list // list_ptr_0->gotoNext(); list_ptr_0->gotoNext(); // 12 3 0401231103013012401240123 list_ptr_2->gotoNext(); list_ptr_2->gotoNext(); // 12 3 0401231103013012401240123 // remove when the current pointer is inside the list // (at the third position now) // list_ptr_0->remove(tmp_item); // 12 0401231103013012401240123 if ((tmp_item->ne(*items[3])) || (list_ptr_0->curr_d->getItem()->ne(*items[0])) || (list_ptr_0->length() != 27)) { return Error::handle(name(), L"remove (inside)", Error::TEST, __FILE__, __LINE__); } list_ptr_2->remove(); // 12 0401231103013012401240123 if ((list_ptr_0->curr_d->getItem()->ne(*items[0])) || (list_ptr_0->length() != 27)) { return Error::handle(name(), L"remove (inside)", Error::TEST, __FILE__, __LINE__); } // go to the end of the list // list_ptr_0->gotoLast(); list_ptr_2->gotoLast(); // remove when the current pointer is at the end of the list // list_ptr_0->remove(tmp_item); // 12040123110301301240124012 if ((list_ptr_0->curr_d != list_ptr_0->last_d) || (list_ptr_0->curr_d->getItem()->ne(*items[2]))) { return Error::handle(name(), L"remove (last)", Error::TEST, __FILE__, __LINE__); } if ((tmp_item->ne(*items[3])) || (list_ptr_0->length() != 26)) { return Error::handle(name(), L"remove (last)", Error::TEST, __FILE__, __LINE__); } list_ptr_2->remove(); // 12040123110301301240124012 if ((list_ptr_2->curr_d != list_ptr_2->last_d) || (list_ptr_2->length() != 26) || (list_ptr_2->curr_d->getItem()->ne(*items[2]))) { return Error::handle(name(), L"remove (last)", Error::TEST, __FILE__, __LINE__); } // test removeLast // list_ptr_0->removeLast(tmp_item); // 1204012311030130124012401 if ((list_ptr_0->curr_d != list_ptr_0->last_d) || (list_ptr_0->curr_d->getItem()->ne(*items[1]))) { return Error::handle(name(), L"removeLast", Error::TEST, __FILE__, __LINE__); } if ((tmp_item->ne(*items[2])) || (list_ptr_0->length() != 25)) { return Error::handle(name(), L"removeLast", Error::TEST, __FILE__, __LINE__); } list_ptr_2->removeLast(); // 1204012311030130124012401 if ((list_ptr_2->curr_d != list_ptr_2->last_d) || (list_ptr_0->length() != 25) || (list_ptr_2->curr_d->getItem()->ne(*items[1]))) { return Error::handle(name(), L"removeLast", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 6. class-specific public methods: // property methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: property methods...\n"); Console::increaseIndention(); } // testing list occupancy methods and the clear method // if (list_ptr_0->isEmpty()) { return Error::handle(name(), L"isEmpty", Error::TEST, __FILE__, __LINE__); } if (list_ptr_2->isEmpty()) { return Error::handle(name(), L"isEmpty", Error::TEST, __FILE__, __LINE__); } // clear the contents of the list // list_ptr_0->clear(); if (!(list_ptr_0->isEmpty()) || list_ptr_0->length() != 0) { return Error::handle(name(), L"clear / isEmpty", Error::TEST, __FILE__, __LINE__); } list_ptr_2->clear(); if (!(list_ptr_2->isEmpty()) || list_ptr_2->length() != 0) { return Error::handle(name(), L"clear / isEmpty", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete list_ptr_0; delete list_ptr_1; delete list_ptr_2; for (long i = 0; i < num_elem; i++) { delete items[i]; } delete [] items; // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 7. class-specific public methods: // ordering methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: ordering methods...\n"); Console::increaseIndention(); } // testing the sort and apply method // DoubleLinkedList<Char> char_list_1; DoubleLinkedList<Char> char_list_2; DoubleLinkedList<Char> char_list_3; Char* low_chars = new Char[10]; Char* up_chars = new Char[10]; unichar low_tmp_char = L'a'; unichar up_tmp_char = L'A'; // initialize the characters and store them in reverse order in two lists // for (long i = 0; i < 10; i++) { low_chars[i].assign(low_tmp_char); // insert the character to the end of the list 1 // char_list_1.insert(&low_chars[i]); // insert the character to the beginning of the list 2 // char_list_2.insertFirst(&low_chars[i]); // insert the uppercase character to the end of the list 3 // up_chars[i].assign(up_tmp_char); char_list_3.insert(&up_chars[i]); // increment the character value // low_tmp_char++; up_tmp_char++; } // reverse the elements in list 2 // char_list_2.reverse(); // the list 2 should be the same as the list 1 now // if (char_list_1.ne(char_list_2)) { char_list_1.debug(L"reversed list_1"); return Error::handle(name(), L"reverse", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 8. class-specific public methods: // apply methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: apply methods...\n"); Console::increaseIndention(); } // apply a method to all the nodes in list 1 // char_list_2.apply(&Char::toUpper, char_list_1); char_list_1.apply(&Char::toUpper); // list 1 should be the same as the list 3 now // if (char_list_1.ne(char_list_3)) { char_list_1.debug(L"upper cased list_1"); return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__); } // list 2 should be the same as the list 3 now // if (char_list_2.ne(char_list_3)) { char_list_2.debug(L"upper cased list_2"); return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__); } // clean up // delete [] low_chars; delete [] up_chars; // test sort and swap methods // DoubleLinkedList<Long> long_list; VectorLong nums(L"5, 3, 2, 6, 4, 1, 3, 7"); for (long i = 0; i < 8; i++) { long_list.insert(&nums(i)); } // test insertion sort algorithm (ascending) // the list now is "1 2 3 3 4 5 6 7" // long_list.sort(Integral::ASCENDING, DoubleLinkedList<Long>::INSERTION); for (long i = 0; i < 7; i++) { if (long_list(i) > long_list(i + 1)) { long_list.debug(L"insertion sort, ascending"); return Error::handle(name(), L"insertion sort", Error::TEST, __FILE__, __LINE__); } } // swap two nodes with values "1" and "6", whose indices are 0 and 6 // long_list.swap(0, 6); if ((long)long_list(0) != 6 || (long)long_list(6) != 1) { long_list.debug(L"swap"); return Error::handle(name(), L"swap", Error::TEST, __FILE__, __LINE__); } // test insertion sort algorithm (descending) // the list now is "7 6 5 4 3 3 2 1" // long_list.sort(Integral::DESCENDING, DoubleLinkedList<Long>::INSERTION); for (long i = 0; i < 7; i++) { if (long_list(i) < long_list(i + 1)) { long_list.debug(L"insertion sort, descending"); return Error::handle(name(), L"insertion sort", Error::TEST, __FILE__, __LINE__); } } // test quick sort algorithm (ascending) // the list now is "1 2 3 3 4 5 6 7" // long_list.sort(Integral::ASCENDING, DoubleLinkedList<Long>::RAND_QUICK); for (long i = 0; i < 7; i++) { if (long_list(i) > long_list(i + 1)) { long_list.debug(L"randQuick sort, ascending"); return Error::handle(name(), L"randQuickSort", Error::TEST, __FILE__, __LINE__); } } // test quick sort algorithm (descending) // the list now is "7 6 5 4 3 3 2 1" // long_list.sort(Integral::DESCENDING, DoubleLinkedList<Long>::RAND_QUICK); for (long i = 0; i < 7; i++) { if (long_list(i) < long_list(i + 1)) { long_list.debug(L"randQuick sort, descending"); return Error::handle(name(), L"randQuickSort", Error::TEST, __FILE__, __LINE__); } } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------- // // 9. print completion message // //--------------------------------------------------------------------- // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } if (level_a > Integral::NONE) { SysString output(L"diagnostics passed for class "); output.concat(name()); output.concat(L"\n"); Console::put(output); } // exit gracefully // return true;}// end of include file//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -