Ignore:
Timestamp:
Mar 15, 2008, 4:22:10 AM (14 years ago)
Author:
Peter
Message:

working on ticket:223

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/distance_test.cc

    r1210 r1233  
    2222*/
    2323
     24#include "Suite.h"
     25
    2426#include "yat/classifier/DataLookupWeighted1D.h"
    2527#include "yat/classifier/MatrixLookupWeighted.h"
     
    3840using namespace theplu::yat;
    3941
    40 int main(const int argc,const char* argv[])
    41 
     42int main(int argc, char* argv[])
    4243
    43   std::ostream* error;
    44   if (argc>1 && argv[1]==std::string("-v"))
    45     error = &std::cerr;
    46   else {
    47     error = new std::ofstream("/dev/null");
    48     if (argc>1)
    49       std::cout << "distance_test -v : for printing extra information\n";
    50   }
    51   *error << "testing distance" << std::endl;
    52   bool ok = true;
     44  theplu::yat::test::Suite suite(argc, argv);
     45  suite.err() << "testing distance" << std::endl;
    5346 
    5447  utility::Vector a(3,1);
     
    6154  double dist=eucl_dist(a.begin(),a.end(),b.begin());
    6255  if(std::abs(dist-2.23607)>tolerance) {
    63     *error << "Error in unweighted Euclidean distance " << std::endl;
    64     ok=false;
     56    suite.err() << "Error in unweighted Euclidean distance " << std::endl;
     57    suite.add(false);
    6558  }
    6659 
     
    6861  dist=pear_dist(a.begin(),a.end(),b.begin());
    6962  if(std::abs(dist-1.5)>tolerance) {
    70     *error << "Error in unweighted Pearson distance " << std::endl;
    71     ok=false;
     63    suite.err() << "Error in unweighted Pearson distance " << std::endl;
     64    suite.add(false);
    7265  }
    7366 
     
    8780 
    8881  if(std::abs(dist-sqrt(6))>tolerance) {
    89     *error << "Error in weighted Euclidean distance " << std::endl;
    90     ok=false;
     82    suite.err() << "Error in weighted Euclidean distance " << std::endl;
     83    suite.add(false);
    9184  }
    9285 
     
    9487 
    9588  if(std::abs(dist-2)>tolerance) {
    96     *error << "Error in weighted Pearson distance " << std::endl;
    97     ok=false;
     89    suite.err() << "Error in weighted Pearson distance " << std::endl;
     90    suite.add(false);
    9891  }
    9992 
     
    107100  dist=eucl_dist(sa.begin(),sa.end(),sb.begin());
    108101  if(std::abs(dist-2.23607)>tolerance) {
    109     *error << "Error in distance for std::vector " << std::endl;
    110     ok=false;
     102    suite.err() << "Error in distance for std::vector " << std::endl;
     103    suite.add(false);
    111104  }
    112105 
     
    116109  dist=eucl_dist(la.begin(),la.end(),sb.begin());
    117110  if(std::abs(dist-2.23607)>tolerance) {
    118     *error << "Error in distance for std::list " << std::endl;
    119     ok=false;
     111    suite.err() << "Error in distance for std::list " << std::endl;
     112    suite.add(false);
    120113  }
    121114 
    122   if(!ok) {
    123     *error << "distance_test failed" << std::endl;
    124   }
    125   if (error!=&std::cerr)
    126     delete error;
    127   if (ok) 
    128     return 0;
    129   return -1;
     115  return suite.return_value();
    130116}
    131117
Note: See TracChangeset for help on using the changeset viewer.