Changeset 1237


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

working on #223

Location:
trunk/test
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/feature_selection_test.cc

    r1210 r1237  
    2323*/
    2424
     25#include "Suite.h"
     26
    2527#include "yat/classifier/DataLookupWeighted1D.h"
    2628#include "yat/classifier/FeatureSelectorIR.h"
     
    4143using namespace theplu::yat;
    4244
    43 int main(const int argc,const char* argv[])
     45int main(int argc, char* argv[])
    4446
    45   std::ostream* error;
    46   if (argc>1 && argv[1]==std::string("-v"))
    47     error = &std::cerr;
    48   else {
    49     error = new std::ofstream("/dev/null");
    50     if (argc>1)
    51       std::cout << "feature_selection -v : for printing extra information\n";
    52   }
    53   *error << "testing feature_selection" << std::endl;
    54   bool ok = true;
     47  test::Suite suite(argc, argv);
     48  suite.err() << "testing feature_selection" << std::endl;
    5549
    5650  statistics::SNRScore snr;
     
    5852  classifier::FeatureSelectorRandom f2(12);
    5953
    60   *error << "Reading in Sorlie data to identify top gene ..." << std::endl;
     54  suite.err() << "Reading in Sorlie data to identify top gene ..." << std::endl;
    6155  std::ifstream is("data/sorlie_centroid_data.txt");
    6256  utility::Matrix data(is,'\t');
     
    6761  is.close();
    6862
    69   *error << "... done" << std::endl;
     63  suite.err() << "... done" << std::endl;
    7064
    7165  // Generate weight matrix with 0 for missing values and 1 for others.
     
    7973 
    8074  f2.update(dataviewweighted,targets);
    81   *error << "\nRandomly ordered features (top 12):\n";
     75  suite.err() << "\nRandomly ordered features (top 12):\n";
    8276  std::vector<size_t> features=f2.features().vector();
    8377  std::copy(features.begin(),features.end(),
    84             std::ostream_iterator<size_t>(*error," "));
    85   *error << std::endl;
     78            std::ostream_iterator<size_t>(suite.err()," ")); 
     79  suite.err() << std::endl;
    8680
    8781  f.update(dataviewweighted,targets);
    88   *error << "\nSNR ordered ordered features (top 12):\n";
     82  suite.err() << "\nSNR ordered ordered features (top 12):\n";
    8983  features=f.features().vector();
    9084  std::copy(features.begin(),features.end(),
    91             std::ostream_iterator<size_t>(*error," "));
    92   *error << std::endl;
     85            std::ostream_iterator<size_t>(suite.err()," ")); 
     86  suite.err() << std::endl;
    9387
    9488  size_t best_feature=features[0];
    9589  if(best_feature!=69) {
    96     *error << "\nERROR: Incorrect best feature found!\n" << std::endl;
    97     ok=0;
     90    suite.err() << "\nERROR: Incorrect best feature found!\n" << std::endl;
     91    suite.add(false);
    9892  }
    9993
     
    10195  double score_diff=std::abs(snr.score(targets,row)-1.47804);
    10296  if(score_diff>0.00001) {
    103     *error << "\nERROR: Best score not what expected!\n" << std::endl;
    104     ok=0;
     97    suite.err() << "\nERROR: Best score not what expected!\n" << std::endl;
     98    suite.add(false);
    10599  }
    106100 
     
    111105  for(size_t i=0;i<features.size();i++) {
    112106    if(features[i]!=i) {
    113       ok=0;
    114       *error << "ERROR: Problem with top-ranked feature" << std::endl;
     107      suite.add(false);
     108      suite.err() << "ERROR: Problem with top-ranked feature" << std::endl;
    115109    }
    116110  }
    117111
    118   if (ok)
    119     return 0;
    120   return -1;
     112  return suite.return_value();
    121113}
  • 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}
  • trunk/test/inputranker_test.cc

    r1121 r1237  
    2424*/
    2525
     26#include "Suite.h"
     27
    2628#include "yat/classifier/InputRanker.h"
    2729#include "yat/statistics/AUC.h"
     
    3436#include <iostream>
    3537
    36 
    37 
    38 int main(const int argc,const char* argv[])
     38int main(int argc, char* argv[])
    3939{
    4040  using namespace theplu::yat;
    41   std::ostream* error;
    42   if (argc>1 && argv[1]==std::string("-v"))
    43     error = &std::cerr;
    44   else {
    45     error = new std::ofstream("/dev/null");
    46     if (argc>1)
    47       std::cout << "inputranker_test -v : for printing extra information\n";
    48   }
    49   *error << "testing inputranker" << std::endl;
    50   bool ok = true;
     41  test::Suite suite(argc, argv);
     42  suite.err() << "testing inputranker" << std::endl;
    5143
    5244  std::ifstream is("data/rank_data.txt");
     
    6254  classifier::InputRanker ir(data,target,roc);
    6355  if (ir.id()[0]!=2 || ir.id()[1]!=0 || ir.id()[2]!=1){
    64     *error << "wrong id" << std::endl;
    65     ok=false;
     56    suite.err() << "wrong id" << std::endl;
     57    suite.add(false);
    6658  }
    6759 
    6860  if (ir.rank()[0]!=1 || ir.rank()[1]!=2 || ir.rank()[2]!=0){
    69     *error << "wrong rank" << std::endl;
    70     ok=false;
     61    suite.err() << "wrong rank" << std::endl;
     62    suite.add(false);
    7163  }
    72  
    73   if (error!=&std::cerr)
    74     delete error;
    75 
    76   return (ok ? 0 : -1);
    77 
     64  return suite.return_value();
    7865}
  • trunk/test/iterator_test.cc

    r1146 r1237  
    2222*/
    2323
     24#include "Suite.h"
     25
    2426#include "yat/classifier/DataLookup1D.h"
    2527
     
    3537using namespace theplu::yat;
    3638
    37 int main(const int argc,const char* argv[])
     39int main(int argc, char* argv[])
    3840
    39   std::ostream* message;
    40   if (argc>1 && argv[1]==std::string("-v"))
    41     message = &std::cerr;
    42   else {
    43     message = new std::ofstream("/dev/null");
    44     if (argc>1)
    45       std::cout << "iterator_test -v : for printing extra "  << "information\n";
    46   }
    47   *message << "testing iterator" << std::endl;
    48   bool ok = true;
     41  test::Suite suite(argc, argv);
     42  suite.err() << "testing iterator" << std::endl;
    4943
    50   *message << "testing utility::vector::iterator" << std::endl;
     44  suite.err() << "testing utility::vector::iterator" << std::endl;
    5145  utility::Vector vec(12);
    5246  classifier::DataLookup1D lookup(vec);
     
    5650  ci = begin;
    5751  if (begin!=ci)
    58     ok = false;
     52    suite.add(false);
    5953
    6054  utility::Vector::iterator end=vec.end();
    6155  std::sort(begin, end);
    6256
    63   *message << "testing classifier::DataLookup1D::const_iterator" << std::endl;
     57  suite.err() << "testing classifier::DataLookup1D::const_iterator" << std::endl;
    6458  classifier::DataLookup1D::const_iterator lbegin=lookup.begin();
    6559  classifier::DataLookup1D::const_iterator lend=lookup.end();
    6660 
    67   *message << "copy from DataLookup1D to Vector" << std::endl;
     61  suite.err() << "copy from DataLookup1D to Vector" << std::endl;
    6862  std::copy(lbegin, lend, begin);
    69   *message << "copy from Vector to Vector" << std::endl;
     63  suite.err() << "copy from Vector to Vector" << std::endl;
    7064  std::copy(begin, end, begin);
    71   *message << "sort Vector" << std::endl;
     65  suite.err() << "sort Vector" << std::endl;
    7266  std::sort(begin, end);
    7367
     
    8175                         std::pair<double, double>(1.0, 1.0));
    8276  if(nof1!=2) {
    83     *message << "std algoritm with IteratorWeighted failed" << std::endl;
    84     ok=false;
     77    suite.err() << "std algoritm with IteratorWeighted failed" << std::endl;
     78    suite.add(false);
    8579  }
    8680  if (aw.begin()!=mw.begin_row(0))
    87     ok = false;
     81    suite.add(false);
    8882  if (aw.end()!=mw.end_row(0))
    89     ok = false;
     83    suite.add(false);
    9084  classifier::DataLookupWeighted1D aw2(mw,0,false);
    9185  if (aw2.begin()!=mw.begin_column(0))
    92     ok = false;
     86    suite.add(false);
    9387  if (aw2.end()!=mw.end_column(0))
    94     ok = false;
     88    suite.add(false);
    9589
    9690  classifier::MatrixLookup ml(m);
    9791  classifier::DataLookup1D dl1(ml,0,true);
    9892  if (dl1.begin()!=ml.begin_row(0))
    99     ok = false;
     93    suite.add(false);
    10094  if (dl1.end()!=ml.end_row(0))
    101     ok = false;
     95    suite.add(false);
    10296  classifier::DataLookup1D dl2(ml,0,false);
    10397  if (dl2.begin()!=ml.begin_column(0))
    104     ok = false;
     98    suite.add(false);
    10599  if (dl2.end()!=ml.end_column(0))
    106     ok = false;
     100    suite.add(false);
    107101
    108   if (!ok)
    109     *message << "iterator test failed" << std::endl;
    110  
    111   return (ok ? 0 : -1);
     102  return suite.return_value();
    112103}
  • trunk/test/kernel_lookup_test.cc

    r1167 r1237  
    2222*/
    2323
     24#include "Suite.h"
     25
    2426#include "yat/utility/Matrix.h"
    2527#include "yat/classifier/DataLookup1D.h"
     
    3537using namespace theplu::yat;
    3638
    37 int main(const int argc,const char* argv[])
     39int main(int argc, char* argv[])
    3840{
    3941  using namespace theplu::yat::classifier;
    4042
    41   std::ostream* error;
    42   if (argc>1 && argv[1]==std::string("-v"))
    43     error = &std::cerr;
    44   else {
    45     error = new std::ofstream("/dev/null");
    46     if (argc>1)
    47       std::cout << "lookup_test -v : for printing extra information\n";
    48   }
     43  theplu::yat::test::Suite suite(argc, argv);
    4944
    50   bool ok =true;
    51   *error << "\nTesting KernelLookup" << std::endl;
     45  suite.err() << "\nTesting KernelLookup" << std::endl;
    5246  utility::Matrix data_core(1,5);
    5347  for (size_t i=0; i<data_core.columns(); i++)
     
    5751  classifier::Kernel_SEV kernel(data,kf);
    5852
    59   *error << "KernelLookup::KernelLookup(const Kernel&)...";
     53  suite.err() << "KernelLookup::KernelLookup(const Kernel&)...";
    6054  classifier::KernelLookup k1(kernel);
    6155  if (k1.rows()!=kernel.size() || k1.columns()!=kernel.size()) {
    62     ok =false;
    63     *error <<   "ERROR:" << std::endl;
    64     *error << "Dimensions do not agree." << std::endl;
     56    suite.add(false);
     57    suite.err() <<  "ERROR:" << std::endl;
     58    suite.err() << "Dimensions do not agree." << std::endl;
    6559  }
    6660  else {
     
    6862      for (size_t j=0; j<k1.columns(); j++)
    6963        if (k1(i,j)!=kernel(i,j)) {
    70           ok =false;
    71           *error << "ERROR:\n"
     64          suite.add(false);
     65          suite.err() << "ERROR:\n"
    7266                 << "KernelLookup::KernelLookup(const Kernel& data)"
    7367                 << std::endl;
    74           *error << "k(" << i << "," << j << ") is " << k1(i,j)
     68          suite.err() << "k(" << i << "," << j << ") is " << k1(i,j)
    7569                 << "expected " << kernel(i,j) << std::endl;
    7670        }
    77     if (ok)
    78       *error << "Ok." << std::endl;
     71    if (suite.ok())
     72      suite.err() << "Ok." << std::endl;
    7973  }
    8074
     
    8680  index_even.push_back(0);
    8781  index_even.push_back(4);
    88   *error << "KernelLookup::KernelLookup(const Kernel&,\n"
     82  suite.err() << "KernelLookup::KernelLookup(const Kernel&,\n"
    8983         << "                           const vector<size_t>&,\n"
    9084         << "                           const vector<size_t>&)...";
     
    9286                              utility::Index(index_even));
    9387  if (k2.rows()!=index_odd.size() || k2.columns()!=index_even.size()) {
    94     ok =false;
    95     *error << "ERROR:" << std::endl;
    96     *error << "Dimensions do not agree." << std::endl;
     88    suite.add(false);
     89    suite.err() << "ERROR:" << std::endl;
     90    suite.err() << "Dimensions do not agree." << std::endl;
    9791  }
    9892  for (size_t i=0; i<k2.rows(); i++)
    9993    for (size_t j=0; j<k2.columns(); j++)
    10094      if (k2(i,j)!=kernel(index_odd[i],index_even[j])) {
    101         ok =false;
    102         *error << "ERROR:\n"
     95        suite.add(false);
     96        suite.err() << "ERROR:\n"
    10397               << "KernelLookup::KernelLookup(const Kernel& data)"
    10498               << std::endl;
    105         *error << "k(" << i << "," << j << ") is " << k2(i,j)
     99        suite.err() << "k(" << i << "," << j << ") is " << k2(i,j)
    106100               << "expected " << kernel(index_odd[i],index_even[j]) << std::endl;
    107101      }
    108   if (ok)
    109     *error << "Ok." << std::endl;
     102  if (suite.ok())
     103    suite.err() << "Ok." << std::endl;
    110104 
    111   *error << "KernelLookup::KernelLookup(const KernelLookup&,\n"
     105  suite.err() << "KernelLookup::KernelLookup(const KernelLookup&,\n"
    112106         << "                           const vector<size_t>&,\n"
    113107         << "                           const vector<size_t>&)...";
     
    115109  classifier::KernelLookup k3(k2,utility::Index(one),utility::Index(one));
    116110  if (k3.rows()!=one.size() || k3.columns()!=one.size()) {
    117     ok =false;
    118     *error <<   "ERROR:" << std::endl;
    119     *error << "Dimensions do not agree." << std::endl;
     111    suite.add(false);
     112    suite.err() <<  "ERROR:" << std::endl;
     113    suite.err() << "Dimensions do not agree." << std::endl;
    120114  }
    121115  else if (k3(0,0)!=k2(1,1)){
    122     ok = false;
    123     *error << "ERROR:\n k3(0,0) found to be " << k3(0,0)
     116    suite.add(false);
     117    suite.err() << "ERROR:\n k3(0,0) found to be " << k3(0,0)
    124118           << " expected " << k2(1,1) << std::endl;
    125119  }
    126120  else
    127     *error << "Ok." << std::endl;
     121    suite.err() << "Ok." << std::endl;
    128122
    129   *error << "KernelLookup::KernelLookup(const KernelLookup&)...";
     123  suite.err() << "KernelLookup::KernelLookup(const KernelLookup&)...";
    130124  classifier::KernelLookup k4(k2);
    131125  if (k4.rows()!=k2.rows() || k4.columns()!=k2.columns()) {
    132     ok =false;
    133     *error <<   "ERROR:" << std::endl;
    134     *error << "Dimensions do not agree." << std::endl;
    135     *error << "Dimension: rows " << k4.rows() << " columns " << k4.columns()
     126    suite.add(false);
     127    suite.err() <<  "ERROR:" << std::endl;
     128    suite.err() << "Dimensions do not agree." << std::endl;
     129    suite.err() << "Dimension: rows " << k4.rows() << " columns " << k4.columns()
    136130           << "\nOriginal: rows " << k2.rows() << " columns " << k2.columns()
    137131           << std::endl;
     
    141135      for (size_t j=0; j<k4.columns(); j++)
    142136        if (k4(i,j)!=k2(i,j)) {
    143           ok =false;
    144           *error << "ERROR:\n"
     137          suite.add(false);
     138          suite.err() << "ERROR:\n"
    145139                 << "KernelLookup::KernelLookup(const KernelLookup&)"
    146140                 << std::endl;
    147           *error << "k(" << i << "," << j << ") is " << k4(i,j)
     141          suite.err() << "k(" << i << "," << j << ") is " << k4(i,j)
    148142                 << "expected " << k2(i,j) << std::endl;
    149143        }
     
    158152  for (size_t s=0; s<k6->rows(); s++)
    159153    for (size_t t=0; t<k6->rows(); t++)
    160       ok = ok && ((*k6)(s,t)==(*k6)(t,s));
     154      suite.add((*k6)(s,t)==(*k6)(t,s));
    161155
    162 
    163   if (ok)
    164     *error << "Ok." << std::endl;
    165 
    166   if (ok)
    167     *error << "Test Ok." << std::endl;
    168   if (error!=&std::cerr)
    169     delete error;
    170   return (ok ? 0 : -1);
     156  return suite.return_value();
    171157}
    172158
Note: See TracChangeset for help on using the changeset viewer.