Ignore:
Timestamp:
Mar 15, 2008, 5:58:34 PM (14 years ago)
Author:
Peter
Message:

working on #223

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/index_test.cc

    r1106 r1237  
    2222*/
    2323
     24#include "Suite.h"
     25
    2426#include "yat/utility/Index.h"
    2527#include "yat/utility/SmartPtr.h"
     
    2931#include <vector>
    3032
    31 int main(const int argc,const char* argv[])
     33int main(int argc, char* argv[])
    3234
    3335  using namespace theplu::yat;
    3436  using utility::Index;
    3537
    36   std::ostream* error;
    37   if (argc>1 && argv[1]==std::string("-v"))
    38     error = &std::cerr;
    39   else {
    40     error = new std::ofstream("/dev/null");
    41     if (argc>1)
    42       std::cout << "index_test -v : for printing extra information\n";
    43   }
    44   bool ok = true;
    45   *error << "testing Index" << std::endl;
     38  test::Suite suite(argc, argv);
     39  suite.err() << "testing Index" << std::endl;
    4640
    4741  Index index;
    4842  if (index.size()){
    49     ok = false;
    50     *error << "Default constructor failed\n";
     43    suite.add(false);
     44    suite.err() << "Default constructor failed\n";
    5145  }
    5246
    5347  Index index2(10);
    5448  if (index2.size()!=10){
    55     ok = false;
    56     *error << "Constructor Index(10) failed\n";
     49    suite.add(false);
     50    suite.err() << "Constructor Index(10) failed\n";
    5751  }
    5852  for (size_t i=0; i<index2.size(); ++i)
    5953    if (index2[i]!=i){
    60       ok = false;
    61       *error << "index[" << i << "]=" << index2[i] << " expected " << i
     54      suite.add(false);
     55      suite.err() << "index[" << i << "]=" << index2[i] << " expected " << i
    6256             << "\n";
    6357    }
     
    7165  Index index3(sp);
    7266  if (index3.size()!=vec.size()){
    73     ok = false;
    74     *error << "Constructor from SmartPtr failed\n";
     67    suite.add(false);
     68    suite.err() << "Constructor from SmartPtr failed\n";
    7569  }
    7670  for (size_t i=0; i<index3.size(); ++i)
    7771    if (index3[i]!=vec[i]){
    78       ok = false;
    79       *error << "index[" << i << "]=" << index3[i] << " expected " << vec[i]
     72      suite.add(false);
     73      suite.err() << "index[" << i << "]=" << index3[i] << " expected " << vec[i]
    8074             << "\n";
    8175    }
    8276
    83   *error << "  testing creation of sub index\n";
     77  suite.err() << "  testing creation of sub index\n";
    8478  Index index4(index2, index3);
    8579  if (index4.size()!=index3.size()){
    86     ok = false;
    87     *error << "failed\n";
     80    suite.add(false);
     81    suite.err() << "failed\n";
    8882  }
    8983  for (size_t i=0; i<index4.size(); ++i)
    9084    if (index4[i]!=index2[index3[i]]){
    91       ok = false;
    92       *error << "index[" << i << "]=" << index4[i] << " expected "
     85      suite.add(false);
     86      suite.err() << "index[" << i << "]=" << index4[i] << " expected "
    9387             << index2[index3[i]] << "\n";
    9488    }
     
    9690  Index index5(index4);
    9791  if (index5.size()!=index4.size()){
    98     ok = false;
    99     *error << "failed\n";
     92    suite.add(false);
     93    suite.err() << "failed\n";
    10094  }
    10195  for (size_t i=0; i<index5.size(); ++i)
    10296    if (index5[i]!=index4[i]){
    103       ok = false;
    104       *error << "index[" << i << "]=" << index5[i] << " expected "
     97      suite.add(false);
     98      suite.err() << "index[" << i << "]=" << index5[i] << " expected "
    10599             << index4[i] << "\n";
    106100    }
    107101   
    108 
    109   if (ok)
    110     *error << "Ok\n";
    111   else
    112     *error << "Test failed\n";
    113 
    114   if (error!=&std::cerr)
    115     delete error;
    116 
    117   if (ok)
    118     return 0;
    119   return -1;
     102  return suite.return_value();
    120103}
Note: See TracChangeset for help on using the changeset viewer.