// file: $isip/class/dstr/BiGraphArc/BiGraphArcDiagnose.h // version: $Id: BiGraphArcDiagnose.h 10636 2007-01-26 22:18:09Z tm334 $ // // make sure definitions are only made once // #ifndef ISIP_BIGRAPH_ARC_DIAGNOSE #define ISIP_BIGRAPH_ARC_DIAGNOSE // isip include files // #ifndef ISIP_BIGRAPH_ARC #include #endif // BiGraphArcDiagnose: a class that contains the diagnose method of // BiGraphArc class. // template class BiGraphArcDiagnose : public BiGraphArc { //--------------------------------------------------------------------------- // // 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 BiGraphArc::name(); } // other static methods // static bool8 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 BiGraphArcDiagnose template class // //----------------------------------------------------------------------------- // // required static methods // //----------------------------------------------------------------------------- // method: diagnose // // arguments: // Integral::DEBUG level: (input) debug level for diagnostics // // return: a bool8 value indicating status // template bool8 BiGraphArcDiagnose::diagnose(Integral::DEBUG level_a) { //---------------------------------------------------------------------- // // 0. preliminaries // //---------------------------------------------------------------------- // output the class name // if (level_a > Integral::NONE) { SysString output(L"diagnosing class "); output.concat(BiGraphArc::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(); } // test the debug methods // BiGraphArc::setDebug(BiGraphArc::debug_level_d); if (level_a > Integral::BRIEF) { Integral::debug(L"debug"); } // default constructor // BiGraphArc def_arc; BiGraphVertex test_vert; def_arc.setVertex(&test_vert); // copy constructor // BiGraphArc copy_arc(def_arc); // all of the constructed vertices should contain the same item now // if (def_arc.vertex_d != copy_arc.vertex_d) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } // check the constructors and destructors for allocating on the dynamic // memory heap // BiGraphArc* def_dyn_arc = new BiGraphArc(); def_dyn_arc->setVertex(&test_vert); // copy constructor // BiGraphArc* copy_dyn_arc = new BiGraphArc(*def_dyn_arc); // all of the constructed nodes should contain the same item now // if (def_dyn_arc->vertex_d != copy_dyn_arc->vertex_d) { return Error::handle(name(), L"constructors", Error::TEST, __FILE__, __LINE__); } // clear some vertices // def_dyn_arc->clear(); def_arc.clear(); copy_dyn_arc->clear(); copy_arc.clear(); // see if we can dynamically delete // delete def_dyn_arc; delete copy_dyn_arc; // test large allocation construction and deletion // if (level_a >= Integral::ALL) { // output an informative message // Console::put(L"\ntesting large chunk memory allocation and deletion:\n"); // set the memory to a strange block size so we can hopefully catch any // frame overrun errors // BiGraphArc::setGrowSize((int32)731); // loop for a large number of times creating and deleting a large number // of vertices at each loop. we create both self-allocating and // non-self-allocating nodes. // for (int32 j = 1; j <= 100; j++) { BiGraphArc** arcs = new BiGraphArc*[j * 100]; // create the vertices // for (int32 i = 0; i < j * 100; i++) { arcs[i] = new BiGraphArc(); } // delete nodes // for (int32 i = (j * 100) - 1; i >= 0; i--) { delete arcs[i]; } delete [] arcs; } // perform the same test using the new[] and delete [] operators // for (int32 j = 1; j <= 100; j++) { // allocate a large number of nodes // BiGraphArc* arcs = new BiGraphArc[j * 100](); // clean up memory // delete [] arcs; } } // test assign methods // BiGraphVertex vert0; BiGraphVertex vert1; BiGraphArc tmp_arc; BiGraphArc* tmp_dyn_arc = new BiGraphArc(); // set the items // Char ch_item(L'X'); vert1.setItem(&ch_item); tmp_dyn_arc->setVertex(&vert1); tmp_dyn_arc->setWeight(0.79); tmp_dyn_arc->setEpsilon(true); // try the copy assign // tmp_arc.assign(*tmp_dyn_arc); if ((tmp_arc.vertex_d != &vert1) || (tmp_dyn_arc->vertex_d != &vert1) || !(tmp_arc.weight_d.almostEqual(0.79)) || !(tmp_dyn_arc->weight_d.almostEqual(0.79)) || !tmp_arc.is_epsilon_d || !tmp_dyn_arc->is_epsilon_d) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // testing remaining required methods // Char chr_item_0(L'A'); BiGraphArc dbg_arc; BiGraphVertex char_vert; char_vert.setItem(&chr_item_0); dbg_arc.setVertex(&char_vert); dbg_arc.setWeight(0.79); dbg_arc.setEpsilon(true); if (level_a >= Integral::ALL) { dbg_arc.debug(L"testing debug method"); } // use the arcs created in the assign method tests // if (!tmp_arc.eq(*tmp_dyn_arc)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // -------------------------------------------------------------------- // // 2. testing class-specific public methods // endpoint vertex get and set methods // // -------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: vertex get/set methods...\n"); Console::increaseIndention(); } // use the arc declared in the testing of assign methods to test // the get methods. the set methods have already been tested via the // assign method tests // if (tmp_arc.getVertex() != &vert1) { return Error::handle(name(), L"getVertex", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // -------------------------------------------------------------------- // // 3. testing class-specific public methods // arc weight get and set methods // // -------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: arc weight get/set methods...\n"); Console::increaseIndention(); } Float temp_weight = tmp_arc.getWeight(); if (!temp_weight.almostEqual(0.79)) { return Error::handle(name(), L"getWeight", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // -------------------------------------------------------------------- // // 4. testing class-specific public methods // arc epsilon flag get and set methods // // -------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: arc epsilon flag get/set methods...\n"); Console::increaseIndention(); } if (!tmp_arc.getEpsilon()) { return Error::handle(name(), L"getEpsilon", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete tmp_dyn_arc; // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------- // // 5. 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