📄 syscomplexdiagnose.h
字号:
// file: $isip/class/system/SysComplex/SysComplexDiagnose.h// version: $Id: SysComplexDiagnose.h,v 1.8 2001/10/18 18:03:12 gao Exp $//// make sure definitions are made only once//#ifndef ISIP_COMPLEX_DIAGNOSE#define ISIP_COMPLEX_DIAGNOSE// isip include files//#ifndef ISIP_COMPLEX#include "SysComplex.h"#endif// isip include files//#ifndef ISIP_CONSOLE#include "Console.h"#endif// SysComplexDiagnose: a class that contains the diagnose method// of SysComplex class.//template<class TObject>class SysComplexDiagnose : public SysComplex<TObject> { //--------------------------------------------------------------------------- // // public constants // //---------------------------------------------------------------------------public: // define the class name // static const SysString 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 SysString& 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: // additional diagnose methods // static boolean diagnose0(Integral::DEBUG debug_level); static boolean diagnose1(Integral::DEBUG debug_level); static boolean diagnose2(Integral::DEBUG debug_level); };// below are all the methods for the SysComplexDiagnose template class//template <class TObject>const SysString SysComplexDiagnose<TObject>::CLASS_NAME(L"SysComplex");template <class TObject>const SysString& SysComplexDiagnose<TObject>::name() { return CLASS_NAME;}//----------------------------------------------------------------------//// required static methods////----------------------------------------------------------------------// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//// this method is a wrapper that tests three specific types: float, double,// and long.//template<class TObject>boolean SysComplexDiagnose<TObject>::diagnose(Integral::DEBUG level_a) { // test the type "float" // diagnose0(level_a); // test the type "double" // diagnose1(level_a); // test the type "long" // diagnose2(level_a); // 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;}// method: diagnose0//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//// this method performs diagnostics for the type "float"//template<class TObject>boolean SysComplexDiagnose<TObject>::diagnose0(Integral::DEBUG level_a) { //---------------------------------------------------------------------- // // preliminaries // //---------------------------------------------------------------------- // output the class name // if (level_a > Integral::NONE) { SysString output(L"diagnosing class "); output.concat(CLASS_NAME); output.concat(L" for the type float: "); Console::put(output); Console::increaseIndention(); } //--------------------------------------------------------------------- // // required public methods: // //--------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put (L"testing class-specific public methods: required methods...\n"); Console::increaseIndention(); } // test constructor // const SysComplex<float> c0(4.0, 2.0); const SysComplex<float> c1(5); const SysComplex<float> c2(0, 3.3); SysComplex<float> t(3.4, 5.6); float r1 = 5; // test copy constructor // SysComplex<float> c3(c0); if (!Integral::almostEqual(c3, c0)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator = (assignment) // c3 = c2; if (!Integral::almostEqual(c3, c2)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------- // // class-specific public methods: other constructors, assignment, // casting, and component extraction methods // //--------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put (L"testing class-specific public methods: assignment, casting...\n"); Console::increaseIndention(); } // test assign // c3.assign(5, 6); if (!Integral::almostEqual(c3, SysComplex<float>(5, 6))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator = (assignment) // c3 = t; if (!Integral::almostEqual(c3, t)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test cast operator // if (!Integral::almostEqual(SysComplex<long>(c0) , SysComplex<long>(4, 2))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test real // if (!Integral::almostEqual(c3.real(), t.real())) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test imag // if (!Integral::almostEqual((double)c2.imag(), 3.3)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test mag // if (!Integral::almostEqual(c0.mag(), 4.4721)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test angle // if (!Integral::almostEqual(c0.angle(), 0.4636)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // class-specific public methods: // accumulative arithmetic functions with SysComplex and TIntegral types // //--------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: accumulative...\n"); Console::increaseIndention(); } // test operator += // c3 = c2; c3 += c0; if (!Integral::almostEqual(c3 , SysComplex<float>(4, 5.3))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator -= // c3 = c2; c3 -= c0; if (!Integral::almostEqual(c3 , SysComplex<float>(-4, 1.3))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator *= // c3 = c2; c3 *= c0; if (!Integral::almostEqual(c3 , SysComplex<float>(-6.6, 13.2))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator /= // if (!Integral::almostEqual(c0 / c2, SysComplex<float>(0.6061, -1.2121))) { return Error::handle(name(), L"operator /", Error::TEST, __FILE__, __LINE__); } // test operator += // c3 = c2; c3 += 2; if (!Integral::almostEqual(c3 , SysComplex<float>(2, 3.3))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator -= // c3 = c2; c3 -= 2; if (!Integral::almostEqual(c3 , SysComplex<float>(-2, 3.3))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator *= // c3 = c2; c3 *= 2; if (!Integral::almostEqual(c3 , SysComplex<float>(0, 6.6))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator /= // c3 = c2; c3 /= 2; if (!Integral::almostEqual(c3 , SysComplex<float>(0, 1.65))) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator ++ (post-increment) // c3 = c1; c3 = c3++; if (!Integral::almostEqual(c3, 5)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator -- (post-decrement) // c3 = c1; c3 = c3--; if (!Integral::almostEqual(c3, 5)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator ++ (pre-increment) // c3 = c1; c3 = ++c3; if (!Integral::almostEqual(c3, 6)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // test operator -- (pre-decrement) // c3 = c1; c3 = --c3; if (!Integral::almostEqual(c3, 4)) { return Error::handle(name(), L"almostEqual", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // class-specific public methods: // relational functions with SysComplex and TIntegral types // //--------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: relational...\n"); Console::increaseIndention(); } // test operator == (equality) // c3 = c2; if (!(c3 == c2)) { return Error::handle(name(), L"operator<", Error::TEST, __FILE__, __LINE__); } // test operator != // c3 = c0; if (c3 != c0) { return Error::handle(name(), L"operator<", Error::TEST, __FILE__, __LINE__); } // test operator < // if (c0 < c2) { return Error::handle(name(), L"operator<", Error::TEST, __FILE__, __LINE__); } // test operator > // if (!(c0 > c2)) { return Error::handle(name(), L"operator>", Error::TEST, __FILE__, __LINE__); } // test operator <= // if (c0 <= c2) { return Error::handle(name(), L"operator<=", Error::TEST, __FILE__, __LINE__); } // test operator >= // if (!(c0 >= c2)) { return Error::handle(name(), L"operator>=",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -