📄 stackdiagnose.h
字号:
} delete temp_ss; } while ((temp_ss = read_char_sss_text.pop()) != (Stack< Stack<Char> >*)NULL) { temp_ss->setAllocationMode(USER); Stack<Char>* temp_s; while ((temp_s = temp_ss->pop()) != (Stack<Char>*)NULL) { temp_s->setAllocationMode(USER); Char* temp_char; while ((temp_char = temp_s->pop()) != (Char*)NULL) { delete temp_char; } delete temp_s; } delete temp_ss; } while ((temp_ss = read_char_sss_bin.pop()) != (Stack< Stack<Char> >*)NULL) { temp_ss->setAllocationMode(USER); Stack<Char>* temp_s; while ((temp_s = temp_ss->pop()) != (Stack<Char>*)NULL) { temp_s->setAllocationMode(USER); Char* temp_char; while ((temp_char = temp_s->pop()) != (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 // Stack<Char>* char_stack = new Stack<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 stacks // for (long i = 0; i < 500; i++) { characters[i].assign(temp_char); // add the character to the stack // char_stack->push(&characters[i]); // increment the character value // temp_char++; } // copy this stack over // Stack<Char>* char_copy_stack = new Stack<Char>; char_copy_stack->assign(*char_stack); // both stacks should be the same // if (!char_stack->eq(*char_copy_stack)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (char_stack->ne(*char_copy_stack)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // now test that ne() works // char_stack->pop(tmp_char_ptr); // the stacks should be different now. // // both stacks should be the same // if (char_stack->eq(*char_copy_stack)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (!char_stack->ne(*char_copy_stack)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete char_stack; delete char_copy_stack; delete [] characters; { // test equality methods for reference mode // Stack<Char>* char_stack = new Stack<Char>(USER); Char* characters = new Char[500]; unichar temp_char = L'a'; // initialize the characters and store them in the stacks // for (long i = 0; i < 500; i++) { characters[i].assign(temp_char); // add the character to the stack // char_stack->push(&characters[i]); // increment the character value // temp_char++; } // copy this stack over // Stack<Char>* char_copy_stack = new Stack<Char>(USER); char_copy_stack->assign(*char_stack); // both stacks should be the same // if (!char_stack->eq(*char_copy_stack)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (char_stack->ne(*char_copy_stack)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // now test that ne() works // char_stack->pop(); // the stacks should be different now. // // both stacks should be the same // if (char_stack->eq(*char_copy_stack)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } if (!char_stack->ne(*char_copy_stack)) { return Error::handle(name(), L"ne", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete char_stack; delete char_copy_stack; delete [] characters; } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 3. class-specific public methods: // manipulation methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: manipulation methods...\n"); Console::increaseIndention(); } // test push, pop, peek and marking methods for reference mode // Stack<Char> pos_stack_1; Stack<Char> pos_stack_2; Stack<Char> pos_stack_3; Stack<Char> pos_stack_4; Stack<Char> temp_clear_stack; // test the various "push" methods // populate the first stack with all of the letters from 'a' - 'n' in // reverse order, marking the 'i' // for (long i = 0; i < 9; i++) { pos_stack_1.push(items[i]); } pos_stack_1.setMark(); for (long i = 9; i < 14; i++) { pos_stack_1.push(items[i]); } // make sure that the top element is the 'n' // if (*pos_stack_1.peek() != *items[13]) { return Error::handle(name(), L"push", Error::TEST, __FILE__, __LINE__); } // make sure that the mark is set // if (!pos_stack_1.markIsSet()) { return Error::handle(name(), L"setMark/markIsSet", Error::TEST, __FILE__, __LINE__); } // populate the second stack with the entire alphabet // pos_stack_2.push(items, num_elem); // populate the third stack with all alphabets as well, but copied from // the second stack // pos_stack_3.push(pos_stack_2); // make sure that the second and third stack are the same // if (!pos_stack_2.eq(pos_stack_3)) { return Error::handle(name(), L"push", Error::TEST, __FILE__, __LINE__); } // pop the first stack to the mark - it should now have 'i' - 'a' on it // pos_stack_1.popToMark(temp_clear_stack); // make sure the top item is the marked item // if (!(pos_stack_1.markIsSet() && pos_stack_1.isMarkedElement())) { return Error::handle(name(), L"isMarkedElement", Error::TEST, __FILE__, __LINE__); } // make sure the top item is the 'i' // if (*pos_stack_1.peek() != *items[8]) { return Error::handle(name(), L"popToMark", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 4. class-specific public methods: // marker positioning methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: marker positioning methods...\n"); Console::increaseIndention(); } // make sure the clearMark method works // pos_stack_1.clearMark(); if (pos_stack_1.markIsSet() || pos_stack_1.isMarkedElement()) { return Error::handle(name(), L"clearMark", Error::TEST, __FILE__, __LINE__); } // mark the item again // pos_stack_1.setMark(); if (!(pos_stack_1.markIsSet() && pos_stack_1.isMarkedElement())) { return Error::handle(name(), L"setMark", Error::TEST, __FILE__, __LINE__); } // pop'ing the item off of the first stack should clear the mark // pos_stack_1.pop(tmp_char_ptr); if (pos_stack_1.markIsSet() || pos_stack_1.isMarkedElement()) { return Error::handle(name(), L"isMarkedElement", Error::TEST, __FILE__, __LINE__); } // put the 'i' back onto the stack so that the first stack holds 'i' - 'a' // pos_stack_1.push(tmp_char_ptr); // the second stack currently holds 'a' - 'z'. pop until we reach the 's' // push the items pop'd onto the fourth stack // while ((pos_stack_2.peek())->ne(*items[18])) { pos_stack_2.pop(tmp_char_ptr); pos_stack_4.push(tmp_char_ptr); } // the second stack now holds 's' - 'z' and the fourth stack now holds // 'r' - 'a'. pop the fourth stack so that it holds 'i' - 'a' // pos_stack_4.pop(temp_clear_stack, 9); // now the first stack holds 'i' - 'a', the second stack holds 's' - 'z', // the fourth stack holds 'i' - 'a' and the third holds 'a' - 'z'. // // call popAll to put all items from the third stack onto the temp stack // pos_stack_3.popAll(temp_clear_stack); // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 5. 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(); } // make sure the third stack is empty // if (!pos_stack_3.isEmpty()) { return Error::handle(name(), L"popAll", Error::TEST, __FILE__, __LINE__); } // now pop elements off of the temp stack until we reach the 'p' // while ((temp_clear_stack.peek())->ne(*items[15])) { temp_clear_stack.pop(tmp_char_ptr); } // pop the 'p' from the temp stack to the third stack // temp_clear_stack.pop(pos_stack_3, 1); // now the first stack should have an 'i' at the top, the second stack // should have a 's' at the top, the third stack should have a 'p' at the // top, and the fourth stack should have a 'i' at the top. put all of these // together to get "isip" // String isip_string_i1, isip_string_s, isip_string_i2, isip_string_p; isip_string_i1.assign(*(pos_stack_1.peek())); isip_string_s.assign(*(pos_stack_2.peek())); isip_string_i2.assign(*(pos_stack_4.peek())); isip_string_p.assign(*(pos_stack_3.peek())); String isip_string; isip_string.concat(isip_string_i1); isip_string.concat(isip_string_s); isip_string.concat(isip_string_i2); isip_string.concat(isip_string_p); // compare the generated string to the set string // String comp_string(L"isip"); if (comp_string.ne(isip_string)) { return Error::handle(name(), L"push/pop/mark methods failed", Error::TEST, __FILE__, __LINE__); } // test the clear, isEmpty and length methods // if (!temp_clear_stack.clear() || !temp_clear_stack.isEmpty() || (temp_clear_stack.length() != (long)0)) { return Error::handle(name(), L"clear, isEmpty, length", Error::TEST, __FILE__, __LINE__); } // check that the length on one of the occupied stacks is valid // if (pos_stack_2.isEmpty() || (pos_stack_2.length() != 8)) { return Error::handle(name(), L"length", Error::TEST, __FILE__, __LINE__); } { // test push, pop, peek and marking methods for reference mode // Stack<Char> pos_stack_1(USER); Stack<Char> pos_stack_2(USER); Stack<Char> pos_stack_3(USER); Stack<Char> pos_stack_4(USER); Stack<Char> temp_clear_stack(USER); // test the various "push" methods
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -