Changeset 1233


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

working on ticket:223

Location:
trunk/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/data_lookup_1d_test.cc

    r1134 r1233  
    2323*/
    2424
     25#include "Suite.h"
     26
    2527#include "yat/utility/Matrix.h"
    2628#include "yat/classifier/DataLookup1D.h"
     
    3840
    3941utility::Matrix matrix(size_t n);
    40 int end_test(std::ostream*, bool);
    4142
    42 int main(const int argc,const char* argv[])
     43int main(int argc, char* argv[])
    4344{
     45  theplu::yat::test::Suite suite(argc, argv);
    4446  using namespace theplu::yat::classifier;
    4547
    46   std::ostream* error;
    47   if (argc>1 && argv[1]==std::string("-v"))
    48     error = &std::cerr;
    49   else {
    50     error = new std::ofstream("/dev/null");
    51     if (argc>1)
    52       std::cout << "lookup_test -v : for printing extra information\n";
    53   }
    54  
    55   *error << "Testing Lookup Classes" << std::endl;
     48  suite.err() << "Testing Lookup Classes" << std::endl;
    5649  bool ok = true;
    5750
    58   *error << "Testing DataLookup1D" << std::endl;
     51  suite.err() << "Testing DataLookup1D" << std::endl;
    5952  utility::Matrix gsl_m1(matrix(5));
    6053  std::vector<size_t> index_odd;
     
    6760  classifier::MatrixLookup m1(gsl_m1,utility::Index(index_odd),
    6861                              utility::Index(index_even));
    69   *error << gsl_m1 << std::endl << '\n';
    70   *error << m1 << std::endl;
    71   *error << "DataLookup1D::DataLookup1D(const MatrixLookup&\n"
     62  suite.err() << gsl_m1 << std::endl << '\n';
     63  suite.err() << m1 << std::endl;
     64  suite.err() << "DataLookup1D::DataLookup1D(const MatrixLookup&\n"
    7265         << "                           const size_t, const bool)...";
    7366  classifier::DataLookup1D v1(m1,1, true);
     
    7568      v1(1)!=m1(1,1) ) {
    7669    ok =false;
    77     *error << "\nERROR" << std::endl;
    78     *error << "size: " << v1.size() << " expected " << m1.columns() << "\n"
     70    suite.err() << "\nERROR" << std::endl;
     71    suite.err() << "size: " << v1.size() << " expected " << m1.columns() << "\n"
    7972           << "v1(0): " << v1(0) << " expected " << m1(1,0) << "\n"
    8073           << "v1(1): " << v1(1) << " expected " << m1(1,1)
     
    8275  }
    8376  else
    84     *error << "Ok" << std::endl;
     77    suite.err() << "Ok" << std::endl;
    8578
    86   *error << "DataLookup1D::DataLookup1D(const MatrixLookup&\n"
     79  suite.err() << "DataLookup1D::DataLookup1D(const MatrixLookup&\n"
    8780         << "                           const size_t, const bool false)...";
    8881  classifier::DataLookup1D v2(m1,1,false);
    8982  if (v2.size()!=m1.rows() || v2(0)!=m1(0,1) || v2(1)!=m1(1,1) ) {
    9083    ok =false;
    91     *error << "\nERROR\n"
     84    suite.err() << "\nERROR\n"
    9285           << "size: " << v2.size() << " expected " << m1.rows() << "\n"
    9386           << "v2(0): " << v2(0) << " expected " << m1(0,1) << "\n"
     
    9689  }
    9790  else
    98     *error << "Ok" << std::endl;
     91    suite.err() << "Ok" << std::endl;
    9992
    100   *error << "DataLookup1D::DataLookup1D(const DataLookup1D&)...";
     93  suite.err() << "DataLookup1D::DataLookup1D(const DataLookup1D&)...";
    10194  classifier::DataLookup1D v3(v2);
    10295  if (v3.size()!=v2.size() || v3(0)!=v2(0) || v3(1)!=v2(1) ) {
    10396    ok =false;
    104     *error << "\nERROR\n"
     97    suite.err() << "\nERROR\n"
    10598           << "size: " << v3.size() << " expected " << v2.size() << "\n"
    10699           << "v2(0): " << v3(0) << " expected " << v2(0) << "\n"
     
    109102  }
    110103  else
    111     *error << "Ok" << std::endl;
     104    suite.err() << "Ok" << std::endl;
    112105
    113   *error << "DataLookup1D::DataLookup1D(const size_t, const double)...";
     106  suite.err() << "DataLookup1D::DataLookup1D(const size_t, const double)...";
    114107  classifier::DataLookup1D v4(12,3);
    115108  if (v4.size()!=12 || v4(10)!=3 ) {
    116109    ok =false;
    117     *error << "\nERROR\n"
     110    suite.err() << "\nERROR\n"
    118111           << "size: " << v4.size() << " expected " << 12 << "\n"
    119112           << "v2(0): " << v4(10) << " expected " << 3
     
    121114  }
    122115  else
    123     *error << "Ok" << std::endl;
     116    suite.err() << "Ok" << std::endl;
    124117
    125   *error << "Testing that output from ostream operator for DataLookup1D"
     118  suite.err() << "Testing that output from ostream operator for DataLookup1D"
    126119         << " can be used by the utility::vector istream constructor...";
    127120
     
    136129      v5(2)!=v1(2)) {
    137130    ok=false;
    138     *error << "\nERROR\n" << std::endl;
     131    suite.err() << "\nERROR\n" << std::endl;
    139132  }
    140133  std::remove("data/tmp_test_datalookup1D.txt");
     
    153146  if (v7.size()!=v6.size() || !std::isnan(v7(1))) {
    154147    ok=false;
    155     *error << "\nERROR\n"
     148    suite.err() << "\nERROR\n"
    156149           << "size: " << v7.size() << " expected " << v6.size() << "\n"
    157150           << "v7(1): " << v7(1) << " expected nan\n"
     
    159152  }
    160153  std::remove("data/tmp_test_datalookup1D.txt");
    161   *error << "\n";
     154  suite.err() << "\n";
    162155
    163156  DataLookup1D dl(v5);
     
    166159  if (!v5.equal(v8,0.0)) {
    167160    ok = false;
    168     *error << "Error: Creating a DataLookup1D(utility::vector)\n"
     161    suite.err() << "Error: Creating a DataLookup1D(utility::vector)\n"
    169162           << "and classifier::convert(DataLookup, utility::vector)\n"
    170163           << "does not give back original vector\n"
     
    175168  }
    176169
    177   return end_test(error,ok);
     170  return suite.return_value();
    178171}
    179172
     
    187180}
    188181
    189 int end_test(std::ostream* error, bool ok)
    190 
    191   if (ok)
    192     *error << "Ok." << std::endl;
    193   if (error!=&std::cerr)
    194     delete error;
    195   return (ok ? 0 : -1);
    196 }
  • 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.