📄 queuediagnose.h
字号:
while ((temp_char = temp_queue2->remove()) != (Char*) NULL) { delete temp_char; } delete temp_queue2; } while ((temp_queue2 = read_char_queue_queue_bin.remove()) != (Queue<Char>*)NULL) { Char temp_char1; while ((temp_queue2->remove(&temp_char1)) != (Char*)NULL) { } delete temp_queue2; } while ((temp_queue2 = read_char_queue_queue_text.remove()) != (Queue<Char>*)NULL) { Char temp_char1; while ((temp_queue2->remove(&temp_char1)) != (Char*)NULL) { } delete temp_queue2; } // delete things from the triple-nested queues // Queue< Queue<Char> >* temp_ss; while ((temp_ss = write_char_sss.remove()) != (Queue< Queue<Char> >*)NULL) { Queue<Char>* temp_s; while ((temp_s = temp_ss->remove()) != (Queue<Char>*)NULL) { Char* temp_char; while ((temp_char = temp_s->remove()) != (Char*)NULL) { delete temp_char; } delete temp_s; } delete temp_ss; } while ((temp_ss = read_char_sss_text.remove()) != (Queue< Queue<Char> >*)NULL) { temp_ss->setAllocationMode(USER); Queue<Char>* temp_s; while ((temp_s = temp_ss->remove()) != (Queue<Char>*)NULL) { temp_s->setAllocationMode(USER); Char* temp_char; while ((temp_char = temp_s->remove()) != (Char*)NULL) { delete temp_char; } delete temp_s; } delete temp_ss; } while ((temp_ss = read_char_sss_bin.remove()) != (Queue< Queue<Char> >*)NULL) { temp_ss->setAllocationMode(USER); Queue<Char>* temp_s; while ((temp_s = temp_ss->remove()) != (Queue<Char>*)NULL) { temp_s->setAllocationMode(USER); Char* temp_char; while ((temp_char = temp_s->remove()) != (Char*)NULL) { delete temp_char; } delete temp_s; } delete temp_ss; } // cleanup dynamically allocated memory // for (long i = 0; i < 5; i++) { delete write_chars[i]; delete write_strings[i]; } delete [] write_chars; delete [] write_strings; // we do not delete wc_ss_0 and wc_ss_1 because they have been deleted // in write_char_sss object } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 2. class-specific public methods: // extensions to required methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: extensions to required methods...\n"); Console::increaseIndention(); } // test equality methods for reference mode // Queue<Char>* char_queue = new Queue<Char>; Char* characters = new Char[500]; unichar temp_char = L'a'; Char* tmp_char_ptr = new Char(); // initialize the characters and store them in the queues // for (long i = 0; i < 500; i++) { characters[i].assign(temp_char); // add the character to the queue // char_queue->add(&characters[i]); // increment the character value // temp_char++; } // copy this queue over // Queue<Char>* char_copy_queue = new Queue<Char>; char_copy_queue->assign(*char_queue); // both queues should be the same // if (!char_queue->eq(*char_copy_queue)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (char_queue->ne(*char_copy_queue)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // now test that ne() works // char_queue->remove(tmp_char_ptr); // the queues should be different now. // // both queues should be the same // if (char_queue->eq(*char_copy_queue)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (!char_queue->ne(*char_copy_queue)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete char_queue; delete char_copy_queue; delete [] characters; { // test equality methods for self-allocation mode // Queue<Char>* char_queue = new Queue<Char>(USER); Char* characters = new Char[500]; unichar temp_char = L'a'; // initialize the characters and store them in the queues // for (long i = 0; i < 500; i++) { characters[i].assign(temp_char); // add the character to the queue // char_queue->add(&characters[i]); // increment the character value // temp_char++; } // copy this queue over // Queue<Char>* char_copy_queue = new Queue<Char>(USER); char_copy_queue->assign(*char_queue); // both queues should be the same // if (!char_queue->eq(*char_copy_queue)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (char_queue->ne(*char_copy_queue)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // now test that ne() works // char_queue->remove(); // the queues should be different now. // // both queues should be the same // if (char_queue->eq(*char_copy_queue)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (!char_queue->ne(*char_copy_queue)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete char_queue; delete char_copy_queue; delete [] characters; } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 3. class-specific public methods: // queue add and remove methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: queue add and remove methods...\n"); Console::increaseIndention(); } // test add, remove, peek and marking methods for self-allocation mode // Queue<Char> pos_queue_1; Queue<Char> pos_queue_2; Queue<Char> pos_queue_3; Queue<Char> pos_queue_4; Queue<Char> temp_clear_queue; // test the various "add" methods in self-allocation mode // populate the first queue with all of the letters from 'a' - 'n' in // reverse order, marking the 'i' // for (long i = 0; i < 9; i++) { pos_queue_1.add(items[i]); } pos_queue_1.setMark(); for (long i = 9; i < 14; i++) { pos_queue_1.add(items[i]); } // make sure that the top element is the 'a' // if (*pos_queue_1.peek() != *items[0]) { return Error::handle(name(), L"add", Error::TEST, __FILE__, __LINE__); } // make sure that the mark is set // if (!pos_queue_1.markIsSet()) { return Error::handle(name(), L"setMark/markIsSet", Error::TEST, __FILE__, __LINE__); } // populate the second queue with the entire alphabet // pos_queue_2.add(items, num_elem); // populate the third queue with all alphabets as well, but copied from // the second queue // pos_queue_3.add(pos_queue_2); // make sure that the second and third queue are the same // if (!pos_queue_2.eq(pos_queue_3)) { return Error::handle(name(), L"add", Error::TEST, __FILE__, __LINE__); } // remove the first queue to the mark - it should now have 'i' - 'n' on it // pos_queue_1.removeToMark(temp_clear_queue); // make sure the top item is the marked item // if (!(pos_queue_1.markIsSet() && pos_queue_1.isMarkedElement())) { pos_queue_1.debug(L"pos_queue_1"); return Error::handle(name(), L"isMarkedElement", Error::TEST, __FILE__, __LINE__); } // make sure the top item is the 'i' // if (*pos_queue_1.peek() != *items[8]) { return Error::handle(name(), L"removeToMark", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 4. class-specific public methods: // queue marker positioning methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: queue marker positioning methods...\n"); Console::increaseIndention(); } // make sure the clearMark method works // pos_queue_1.clearMark(); if (pos_queue_1.markIsSet() || pos_queue_1.isMarkedElement()) { return Error::handle(name(), L"clearMark", Error::TEST, __FILE__, __LINE__); } // mark the item again, the 'n' is marked // pos_queue_1.setMark(); // the second queue currently holds 'a' - 'z'. remove until we reach the 'r' // add the items removed onto the fourth queue // while ((pos_queue_2.peek())->ne(*items[18])) { pos_queue_2.remove(tmp_char_ptr); pos_queue_4.add(tmp_char_ptr); } // the second queue now holds 'r' - 'z' and the fourth queue now holds // 'a' - 'q'. remove the fourth queue so that it holds 'j' - 'q' // pos_queue_4.remove(temp_clear_queue, 9); // now the first queue holds 'i' - 'n', the second queue holds 's' - 'z', // the third queue holds 'a' - 'z' and the fourth holds 'j' - 'q'. // // call removeAll to put all items from the third queue onto the temp queue // pos_queue_3.removeAll(temp_clear_queue); // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 5. class-specific public methods: // queue property methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: queue property methods...\n"); Console::increaseIndention(); } // make sure the third queue is empty // if (!pos_queue_3.isEmpty()) { return Error::handle(name(), L"removeAll", Error::TEST, __FILE__, __LINE__); } // now remove elements off of the temp queue until we reach the 'p' // while ((temp_clear_queue.peek())->ne(*items[15])) { temp_clear_queue.remove(tmp_char_ptr); } // remove the 'p' from the temp queue and add to the third queue // temp_clear_queue.remove(pos_queue_3, 1); // now the first queue should have an 'i' at the top, the second queue // should have a 's' at the top, the third queue should have a 'p' at the // top, and the fourth queue should have a 'j' at the top. // if (pos_queue_1.peek()->ne(*items[8]) || pos_queue_1.length() != 6) { return Error::handle(name(), L"add/remove/mark methods failed", Error::TEST, __FILE__, __LINE__); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -