📄 treediagnose.h
字号:
// file: $isip/class/dstr/Tree/TreeDiagnose.h// version: $Id: TreeDiagnose.h,v 1.3 2002/08/26 18:37:37 alphonso Exp $//// make sure definitions are only made once//#ifndef ISIP_TREE_DIAGNOSE#define ISIP_TREE_DIAGNOSE// isip include files//#ifndef ISIP_TREE#include <Tree.h>#endif// TreeDiagnose: a class that contains the diagnose method of Tree class.//template<class TObject>class TreeDiagnose : public Tree<TObject> { //--------------------------------------------------------------------------- // // public constants // //---------------------------------------------------------------------------public: // define the class name // //---------------------------------------- // // i/o related constants // //---------------------------------------- //---------------------------------------- // // default values and arguments // //---------------------------------------- // default values // // default arguments to methods // //---------------------------------------- // // error codes // //---------------------------------------- //--------------------------------------------------------------------------- // // protected data // //---------------------------------------------------------------------------protected: //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // method: name // static const String& name() { return Tree<TObject>::name(); } // other static methods // static boolean diagnose(Integral::DEBUG debug_level); // debug methods // these methods are omitted since this class does not have data // members and operations // // destructor/constructor(s): // these methods are omitted since this class does not have data // members and operations // // assign methods: // these methods are omitted since this class does not have data // members and operations // // operator= methods: // these methods are omitted since this class does not have data // members and operations // // i/o methods: // these methods are omitted since this class does not have data // members and operations // // equality methods: // these methods are omitted since this class does not have data // members and operations // // memory-management methods: // these methods are omitted since this class does not have data // members and operations // //--------------------------------------------------------------------------- // // class-specific public methods // //--------------------------------------------------------------------------- // these methods are omitted since this class does not have data // members and operations // //--------------------------------------------------------------------------- // // private methods // //---------------------------------------------------------------------------private:}; // below are all the methods for the TreeDiagnose template class////-----------------------------------------------------------------------------//// required static methods////-----------------------------------------------------------------------------// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//template<class TObject>boolean TreeDiagnose<TObject>::diagnose(Integral::DEBUG level_a) { //--------------------------------------------------------------------------- // // 0. preliminaries // //--------------------------------------------------------------------------- // output the class name // if (level_a > Integral::NONE) { SysString output(L"diagnosing class "); output.concat(CLASS_NAME); output.concat(L": "); Console::put(output); Console::increaseIndention(); } //--------------------------------------------------------------------- // // 1. required public methods // //--------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing required public methods...\n"); Console::increaseIndention(); } // create an example tree // // ROOT -> 'a' // -> 'b' -> 'd' // -> 'c' -> 'e' // -> 'f' // Char* char_a = new Char('a'); Char* char_b = new Char('b'); Char* char_c = new Char('c'); Char* char_d = new Char('d'); Char* char_e = new Char('e'); Char* char_f = new Char('f'); // test the default constructors // Tree<Char> tree_00; TreeNode<Char>* node_b = (TreeNode<Char>*)NULL; TreeNode<Char>* node_c = (TreeNode<Char>*)NULL; // test the insert and insert child methods // tree_00.insertChild(tree_00.getRoot(), tree_00.insert(char_a)); node_b = tree_00.insert(char_b); tree_00.insertChild(tree_00.getRoot(), node_b); node_c = tree_00.insert(char_c); tree_00.insertChild(tree_00.getRoot(), node_c); tree_00.insertChild(node_b, tree_00.insert(char_d)); tree_00.insertChild(node_c, tree_00.insert(char_e)); tree_00.insertChild(node_c, tree_00.insert(char_f)); // test the copy constructor // Tree<Char> tree_01(tree_00); // the two tree structures must be equal // if (!tree_00.eq(tree_01)) { return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__); } // test the get method // Vector<Ulong> root_adj_00; SingleLinkedList<Char> node_obj_00; SingleLinkedList<Vector<Ulong> > node_adj_00; tree_00.get(root_adj_00, node_obj_00, node_adj_00); // test the set method // Tree<Char> tree_02; Vector<Ulong> root_adj_01; SingleLinkedList<Char> node_obj_01; SingleLinkedList<Vector<Ulong> > node_adj_01; tree_02.set(root_adj_00, node_obj_00, node_adj_00); // the two tree structures must be equal // if (!tree_00.eq(tree_02)) { return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__); } // free allocated memory // delete char_a; delete char_b; delete char_c; delete char_d; delete char_e; delete char_f; { // create an example tree // // ROOT -> 'a' // -> 'b' -> 'd' // -> 'c' -> 'e' // -> 'f' // Char* char_a = new Char('a'); Char* char_b = new Char('b'); Char* char_c = new Char('c'); Char* char_d = new Char('d'); Char* char_e = new Char('e'); Char* char_f = new Char('f'); // test the default constructors // Tree<Char> tree_00(DstrBase::USER); TreeNode<Char>* node_b = (TreeNode<Char>*)NULL; TreeNode<Char>* node_c = (TreeNode<Char>*)NULL; // test the insert and insert child methods // tree_00.insertChild(tree_00.getRoot(), tree_00.insert(char_a)); node_b = tree_00.insert(char_b); tree_00.insertChild(tree_00.getRoot(), node_b); node_c = tree_00.insert(char_c); tree_00.insertChild(tree_00.getRoot(), node_c); tree_00.insertChild(node_b, tree_00.insert(char_d)); tree_00.insertChild(node_c, tree_00.insert(char_e)); tree_00.insertChild(node_c, tree_00.insert(char_f)); // test the copy constructor // Tree<Char> tree_01(tree_00); // the two tree structures must be equal // if (!tree_00.eq(tree_01)) { return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__); } // test the get method // Vector<Ulong> root_adj_00; SingleLinkedList<Char> node_obj_00; SingleLinkedList<Vector<Ulong> > node_adj_00; tree_00.get(root_adj_00, node_obj_00, node_adj_00); // test the set method // Tree<Char> tree_02(DstrBase::USER); Vector<Ulong> root_adj_01; SingleLinkedList<Char> node_obj_01; SingleLinkedList<Vector<Ulong> > node_adj_01; tree_02.set(root_adj_00, node_obj_00, node_adj_00); // the two tree structures must be equal // if (!tree_00.eq(tree_02)) { return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__); } // free allocated memory // delete char_a; delete char_b; delete char_c; delete char_d; delete char_e; delete char_f; } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------- // // 2. tree manipulation methods // //--------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing tree manipulation methods...\n"); Console::increaseIndention(); } // create an example tree // // ROOT -> '0' // -> '1' -> '3' -> '8' // -> '9' // -> '4' // -> '5' -> '10' // -> '2' -> '6' // -> '7' -> '11' // -> '12' // Ulong* ulong_0 = new Ulong(0); Ulong* ulong_1 = new Ulong(1); Ulong* ulong_2 = new Ulong(2); Ulong* ulong_3 = new Ulong(3); Ulong* ulong_4 = new Ulong(4); Ulong* ulong_5 = new Ulong(5); Ulong* ulong_6 = new Ulong(6); Ulong* ulong_7 = new Ulong(7); Ulong* ulong_8 = new Ulong(8); Ulong* ulong_9 = new Ulong(9); Ulong* ulong_10 = new Ulong(10); Ulong* ulong_11 = new Ulong(11); Ulong* ulong_12 = new Ulong(12); Tree<Ulong> tree_03; TreeNode<Ulong>* node_1 = (TreeNode<Ulong>*)NULL; TreeNode<Ulong>* node_2 = (TreeNode<Ulong>*)NULL; TreeNode<Ulong>* node_3 = (TreeNode<Ulong>*)NULL; TreeNode<Ulong>* node_5 = (TreeNode<Ulong>*)NULL; TreeNode<Ulong>* node_7 = (TreeNode<Ulong>*)NULL; // ROOT -> 0 tree_03.insertChild(tree_03.getRoot(), tree_03.insert(ulong_0)); // ROOT -> 1 node_1 = tree_03.insert(ulong_1); tree_03.insertChild(tree_03.getRoot(), node_1); // 1 -> 3 node_3 = tree_03.insert(ulong_3); tree_03.insertChild(node_1, node_3); // 3 -> 8 tree_03.insertChild(node_3, tree_03.insert(ulong_8)); // 3 -> 9 tree_03.insertChild(node_3, tree_03.insert(ulong_9)); // 1 -> 4 tree_03.insertChild(node_1, tree_03.insert(ulong_4)); // 1 -> 5 node_5 = tree_03.insert(ulong_5); tree_03.insertChild(node_1, node_5);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -