📄 ftrf_02.cc
字号:
// file: $isip/class/mmedia/FeatureFile/ftrf_02.cc// version: $Id: ftrf_02.cc,v 1.7 2002/12/31 16:16:10 parihar Exp $//// isip include files//#include "FeatureFile.h"#include <String.h>#include <Console.h>#include <Filename.h>// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean FeatureFile::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(); } // test the constructor and memory management // FeatureFile ftrs; FeatureFile::setGrowSize((long)500); for (long j = 1; j <= 10; j++) { FeatureFile** ftrs = new FeatureFile*[j * 100]; // create the objects // for (long i = 0; i < j * 100; i++) { ftrs[i] = new FeatureFile(); } // delete objects // for (long i = (j * 100) - 1; i >= 0; i--) { delete ftrs[i]; } delete [] ftrs; } //-------------------------------------------------------------------------- // // 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(); } // test the i/o methods // FeatureFile ftr; ftr.name_d.assign(L"stuff"); ftr.setNumChannels(2); // 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); ftr.write(tmp_file0, (long)0); ftr.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); FeatureFile ftr1; FeatureFile ftr2; // try to do a read // FeatureFile ftr1a; FeatureFile ftr1b; // read the value back // if ((!ftr1.read(tmp_file0, (long)0)) || (!ftr1.eq(ftr))) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if ((!ftr2.read(tmp_file1, (long)0)) || (!ftr2.eq(ftr))) { ftr2.debug(L"ftr2"); ftr.debug(L"ftr"); 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. required public methods // partial i/o methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing required public methods: partial i/o methods...\n"); Console::increaseIndention(); } // output message // if (level_a > Integral::NONE) { Console::put(L"testing sof features partial writing methods in text...\n"); } // want a really big vector for i/o testing // long num_floats = 3050; FeatureFile float_vec; float_vec.setLength(num_floats); for (long i = 0; i < num_floats; i++) { float_vec(i).makeVectorFloat().setLength(7); float_vec(i).getVectorFloat().assign(i * 2.357); } // need binary text sof file // Filename text_filename; Integral::makeTemp(text_filename); File::registerTemp(text_filename); // open files in write mode // float_vec.setFileType(TEXT); float_vec.open(text_filename, File::WRITE_ONLY); float_vec.writePartialData(0, 50); for (long i = 0; i < 30; i++) { float_vec.writePartialData(50 + i * 100, 100); } // close the files // float_vec.close(); // output message // if (level_a > Integral::NONE) { Console::put(L"testing sof features partial writing methods in binary...\n"); } Filename bin_filename; Integral::makeTemp(bin_filename); File::registerTemp(bin_filename); // open files in write mode // float_vec.setFileType(BINARY); float_vec.open(bin_filename, File::WRITE_ONLY); float_vec.writePartialData(0, 50); for (long i = 0; i < 30; i++) { float_vec.writePartialData(50 + i * 100, 100); } float_vec.close(); // output message // if (level_a > Integral::NONE) { Console::put(L"testing sof features additional and partial reading methods in binary...\n"); } // partial read for Vector<Float> // FeatureFile read_float_vec_bin; read_float_vec_bin.setFileType(BINARY); read_float_vec_bin.open(bin_filename, File::READ_ONLY); Vector<AlgorithmData> vf_read; Vector<AlgorithmData> vf_expected; long read_size = 50; FeatureFile vecf_expected; vecf_expected.setLength(read_size); VectorLong start_positions(L"0, 3, 98, 99, 100, 130, 180, 290, 340, 391, 443, 980, 1273, 1993, 2000, 2100, 841"); vf_expected.setLength(read_size); for (long j = 0; j < start_positions.length(); j++) { long start = start_positions(j); for (long i = 0; i < read_size; i++) { // overwrite each time we read in this loop // vecf_expected(i) = float_vec(i + start); vf_expected(i).makeVectorFloat() = float_vec(i + start).getVectorFloat(); } // end of i loop // test the readPartialData method // if (!read_float_vec_bin.readPartialData(start, read_size) || !(read_float_vec_bin.v_d.eq(vecf_expected.v_d))) { read_float_vec_bin.v_d.debug(L"read_float_vec_bin"); vecf_expected.v_d.debug(L"vecf_expected"); return Error::handle(name(), L"readPartialData float bin", Error::TEST, __FILE__, __LINE__); } // test the readFeatureData method // vf_read.clear(); read_float_vec_bin.readFeatureData(vf_read, start, read_size); if (!vf_read.eq(vf_expected)) { vf_read.debug(L"vf_read"); vf_expected.debug(L"vecf_expected"); return Error::handle(name(), L"readFeatureData float bin", Error::TEST, __FILE__, __LINE__); } } // end of j loop // close the files // read_float_vec_bin.close(); // output message // if (level_a > Integral::NONE) { Console::put(L"testing sof features additional and partial reading methods in text...\n"); } // partial read for Vector<Float> // FeatureFile read_float_vec_text; read_float_vec_text.setFileType(TEXT); read_float_vec_text.open(text_filename, File::READ_ONLY); for (long j = 0; j < start_positions.length(); j++) { long start = start_positions(j); for (long i = 0; i < read_size; i++) { // overwrite each time we read in this loop // vecf_expected(i) = float_vec(i + start); vf_expected(i).makeVectorFloat() = float_vec(i + start).getVectorFloat(); } // end of i loop // test the readPartialData method // boolean flag1 = read_float_vec_text.readPartialData(start, read_size); boolean flag2 = true; VectorFloat vec1; VectorFloat vec2; // there is no almostEqual method in the vector // if (read_float_vec_text.v_d.length() != vecf_expected.v_d.length()) { flag2 = false; } for (long k = 0; flag2 && (k < read_float_vec_text.v_d.length()); k++) { vec1 = read_float_vec_text(k).getVectorFloat(); vec2 = read_float_vec_text(k).getVectorFloat(); if(!vec1.almostEqual(vec2, 2)) { flag2 = false; } } if (!flag1 || !flag2) { read_float_vec_text.v_d.debug(L"read_float_vec_text"); vecf_expected.v_d.debug(L"vecf_expected"); return Error::handle(name(), L"readPartialData float text", Error::TEST, __FILE__, __LINE__); } // test the readFeatureData method // vf_read.clear(); flag1 = read_float_vec_text.readFeatureData(vf_read, start, read_size); // there is no almostEqual method in the vector // if (vf_read.length() != vf_expected.length()) { flag2 = false; } for (long k = 0; flag2 && (k < vf_read.length()); k++) { vec1 = vf_read(k).getVectorFloat(); vec2 = vf_expected(k).getVectorFloat(); if(!vec1.almostEqual(vec2, 2)) { flag2 = false; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -