Ignore:
Timestamp:
Mar 20, 2008, 12:07:30 AM (14 years ago)
Author:
Peter
Message:

fixes tests - ticket:223

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/target_test.cc

    r1134 r1248  
    2222*/
    2323
     24#include "Suite.h"
     25
    2426#include "yat/classifier/Target.h"
    2527#include "yat/utility/Index.h"
     
    3234using namespace theplu::yat;
    3335
    34 int main(const int argc,const char* argv[])
     36int main( int argc, char* argv[])
    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 << "target_test -v : for printing extra information\n";
    43   }
    44   *error << "testing target" << std::endl;
    45   bool ok = true;
     38  test::Suite suite(argc, argv);
     39  suite.err() << "testing target" << std::endl;
    4640
    4741  // This test assumes classes are introduced in order of appearence
     
    6054  for (size_t i=0; i<facit.size(); i++){
    6155    if (target3(i)!=facit[i]){
    62       ok=false;
    63       *error << "target(" << i << ") is " << target3(0) << " expected "
     56      suite.add(false);
     57      suite.err() << "target(" << i << ") is " << target3(0) << " expected "
    6458             << facit[i] << std::endl;
    6559    }
     
    7064  classifier::Target sub_target(target3,utility::Index(sub));
    7165  if (target3(sub[0])!=sub_target(0) || target3(sub[1])!=sub_target(1)){
    72     ok = false;
    73     *error << "error in constructor Target(const Target&, std::vector<size_t>&)"
     66    suite.add(false);
     67    suite.err() << "error in constructor Target(const Target&, std::vector<size_t>&)"
    7468           << "\nclasses are not preserved" << std::endl;
    7569  }
    7670  if (target3.binary(sub[0])!=sub_target.binary(0) ||
    7771      target3.binary(sub[1])!=sub_target.binary(1)){
    78     ok = false;
    79     *error << "error in constructor Target(const Target&, std::vector<size_t>&)"
     72    suite.add(false);
     73    suite.err() << "error in constructor Target(const Target&, std::vector<size_t>&)"
    8074           << "\nbinary classes are not preserved" << std::endl;
    8175  }
     
    8882  classifier::Target target(label);
    8983  if (target.nof_classes()!=3){
    90     ok=false;
    91     *error << "Expected number of classes to be 3" << std::endl;
     84    suite.add(false);
     85    suite.err() << "Expected number of classes to be 3" << std::endl;
    9286  }
    9387  if (target(0)!=0){
    94     ok=false;
    95     *error << "Error: target(0)!=0" << std::endl;
     88    suite.add(false);
     89    suite.err() << "Error: target(0)!=0" << std::endl;
    9690  }
    9791  if (target(20)!=2){
    98     ok=false;
    99     *error << "Error: target(20)!=2" << std::endl;
     92    suite.add(false);
     93    suite.err() << "Error: target(20)!=2" << std::endl;
    10094  }
    10195  if (!target.binary(0)){
    102     ok=false;
    103     *error << "Error: target.binary(0) not true" << std::endl;
     96    suite.add(false);
     97    suite.err() << "Error: target.binary(0) not true" << std::endl;
    10498  }   
    10599  if (target.binary(20)){
    106     ok=false;
    107     *error << "Error: target.binary(20) not false" << std::endl;
     100    suite.add(false);
     101    suite.err() << "Error: target.binary(20) not false" << std::endl;
    108102  }   
    109103  target.set_binary(2,true);
    110104  if (!target.binary(20)){
    111     ok=false;
    112     *error << "Error: target.binary(20) not true" << std::endl;
     105    suite.add(false);
     106    suite.err() << "Error: target.binary(20) not true" << std::endl;
    113107  }   
    114108  std::ifstream is("data/rank_target.txt");
     
    116110  is.close();
    117111  if (target2.size()!=6){
    118     ok=false;
    119     *error << "ERROR: size of target is " << target2.size() << " expected 6."
    120           << std::endl;
     112    suite.add(false);
     113    suite.err() << "ERROR: size of target is " << target2.size()
     114                << " expected 6." << std::endl;
    121115  }   
    122116
    123   if (ok)
    124     return 0;
    125   return -1;
     117  suite.return_value();
    126118}
Note: See TracChangeset for help on using the changeset viewer.