#include "HistogramTest.h" #include #include // for cout #include // for setprecision( int p ) #include // For auto_ptr #include #include #include // For system independent path support namespace bf = boost::filesystem; #include "svm_rbf.h" using namespace std; CPPUNIT_TEST_SUITE_REGISTRATION( HistogramTest ); HistogramTest::HistogramTest() : deception(NULL) { } HistogramTest::~HistogramTest() { } /** */ void HistogramTest::setUp() { deception = new mpt::Deception( "ay.txt", "vs.txt" ); } /** */ void HistogramTest::tearDown() { if( deception ) delete deception; } void HistogramTest::testRandomGabor() { mpt::vectorD3D gabor(12); double val=-1.623; double step=4.6510e-04; for( unsigned int i = 0; i < 12; ++i ) { gabor[i].resize(23); for( unsigned int j = 0; j < 23; ++j ) { gabor[i][j].resize(32); for( unsigned int k = 0; k < 32; ++k ) { gabor[i][j][k] = val; val += step; } } } const double d = 1.26; const int b = 4; mpt::vectorD1D hist; hist = deception->newhist( gabor, d, b ); // make sure it's the right size CPPUNIT_ASSERT( mpt::svm_rbf::feature_vector_length == hist.size() ); // load the output from matlab // compare with what we got mpt::vectorD1D goodHist = deception->loadHistogram( "goodHistogram.txt" ); CPPUNIT_ASSERT( mpt::svm_rbf::feature_vector_length == goodHist.size() ); double diff = 0.0; for( unsigned int i = 0; i < hist.size(); ++i ) { diff += abs( hist[i] - goodHist[i] ); } // diff is probably somewhere around 1e10-7 CPPUNIT_ASSERT( diff < 0.00001 ); }