📄 spec_02.cc
字号:
// file: $isip/class/algo/Spectrum/spec_02.cc// version: $Id: spec_02.cc,v 1.19 2002/07/12 03:51:03 parihar Exp $//// isip include files//#include "Spectrum.h"#include <Console.h>// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean Spectrum::diagnose(Integral::DEBUG level_a) { //--------------------------------------------------------------------- // // 0. preliminaries // //--------------------------------------------------------------------- // output the class name // if (level_a > Integral::NONE) { String output(L"diagnosing class "); output.concat(CLASS_NAME); output.concat(L": "); Console::put(output); Console::increaseIndention(); } //-------------------------------------------------------------------------- // // 1. required public methods // class constructors // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing required public methods...\n"); Console::increaseIndention(); } // test destructor/constructor(s) and memory management // Spectrum spec0; spec0.setAlgorithm(MAXIMUM_ENTROPY); spec0.setImplementation(COMPLEX); spec0.setDynRange((float)32); spec0.setFtOrder((long)64); Spectrum spec1(spec0); if (!spec1.eq(spec0)) { return Error::handle(name(), L"copy constructor", Error::TEST, __FILE__, __LINE__); } // test large allocation construction and deletion // if (level_a > Integral::BRIEF) { Console::put(L"testing large chunk memory allocation and deletion:\n"); // set the memory to a strange block size so we can hopefully catch any // frame overrun errors // Spectrum::setGrowSize((long)500); Spectrum* pft = new Spectrum(); for (long j = 1; j <= 100; j++) { Spectrum** pfts = new Spectrum*[j * 100]; // create the objects // for (long i = 0; i < j * 100; i++) { pfts[i] = new Spectrum(); } // delete objects // for (long i = (j * 100) - 1; i >= 0; i--) { delete pfts[i]; } delete [] pfts; } delete pft; } //-------------------------------------------------------------------------- // // 2. required public methods // i/o methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing required public methods: i/o methods...\n"); Console::increaseIndention(); } // we need binary and text sof files // String tmp_filename0; Integral::makeTemp(tmp_filename0); String tmp_filename1; Integral::makeTemp(tmp_filename1); // open files in write mode // Sof tmp_file0; tmp_file0.open(tmp_filename0, File::WRITE_ONLY, File::TEXT); Sof tmp_file1; tmp_file1.open(tmp_filename1, File::WRITE_ONLY, File::BINARY); if (level_a > Integral::BRIEF) { spec0.debug(L"spec0"); } // write to sof file // spec0.write(tmp_file0, (long)0); spec0.write(tmp_file1, (long)0); // close the files // tmp_file0.close(); tmp_file1.close(); // open the files in read mode // tmp_file0.open(tmp_filename0); tmp_file1.open(tmp_filename1); // read the value back // spec1.read(tmp_file0, (long)0); if (!spec1.eq(spec0)) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } // close and delete the temporary files // tmp_file0.close(); tmp_file1.close(); File::remove(tmp_filename0); File::remove(tmp_filename1); // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 3. class-specific public methods: // set and get methods // //--------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: set and get methods...\n"); Console::increaseIndention(); } // set the parameters // spec0.setAlgorithm(FOURIER); spec0.setImplementation(MAGNITUDE); spec0.setDynRange(Prediction::DEF_DYN_RANGE); spec0.setFtAlgorithm(FourierTransform::DEF_ALGORITHM); spec0.setFtImplementation(FourierTransform::DEF_IMPLEMENTATION); spec0.setFtOrder(FourierTransform::DEF_ORDER); // check that the values were set // if (spec0.algorithm_d != FOURIER) { return Error::handle(name(), L"setAlgorithm", Error::TEST, __FILE__, __LINE__); } else if (spec0.implementation_d != MAGNITUDE) { return Error::handle(name(), L"setImplementation", Error::TEST, __FILE__, __LINE__); } else if (spec0.dyn_range_d != Prediction::DEF_DYN_RANGE) { return Error::handle(name(), L"setDynRange", Error::TEST, __FILE__, __LINE__); } else if (spec0.ft_d.getAlgorithm() != FourierTransform::DEF_ALGORITHM) { return Error::handle(name(), L"setFtAlgorithm", Error::TEST, __FILE__, __LINE__); } else if (spec0.ft_d.getImplementation() != FourierTransform::DEF_IMPLEMENTATION) { return Error::handle(name(), L"setFtImplemtation", Error::TEST, __FILE__, __LINE__); } else if (spec0.ft_d.getOrder() != FourierTransform::DEF_ORDER) { return Error::handle(name(), L"setFtOrder", Error::TEST, __FILE__, __LINE__); } // check that the values we'll get // if (spec0.getAlgorithm() != FOURIER) { return Error::handle(name(), L"getAlgorithm", Error::TEST, __FILE__, __LINE__); } else if (spec0.getImplementation() != MAGNITUDE) { return Error::handle(name(), L"getImplementation", Error::TEST, __FILE__, __LINE__); } else if (spec0.getDynRange() != Prediction::DEF_DYN_RANGE) { return Error::handle(name(), L"getDynRange", Error::TEST, __FILE__, __LINE__); } else if (spec0.getFtAlgorithm() != FourierTransform::DEF_ALGORITHM) { return Error::handle(name(), L"getFtAlgorithm", Error::TEST, __FILE__, __LINE__); } else if (spec0.getFtImplementation() != FourierTransform::DEF_IMPLEMENTATION) { return Error::handle(name(), L"getFtImplemtation", Error::TEST, __FILE__, __LINE__); } else if (spec0.getFtOrder() != FourierTransform::DEF_ORDER) { return Error::handle(name(), L"getFtOrder", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 4. class-specific public methods: // computation methods // //--------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: computational methods...\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -