Ignore:
Timestamp:
Mar 16, 2008, 6:21:39 AM (14 years ago)
Author:
Peter
Message:

working on #223

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/matrix_test.cc

    r1151 r1240  
    2424*/
    2525
     26#include "Suite.h"
     27
    2628#include "yat/utility/Matrix.h"
    2729
     
    4648
    4749
    48 int main(const int argc,const char* argv[])
     50int main(int argc, char* argv[])
    4951{
    5052  using namespace theplu::yat;
    51   std::ostream* error;
    52   if (argc>1 && argv[1]==std::string("-v"))
    53     error = &std::cerr;
    54   else {
    55     error = new std::ofstream("/dev/null");
    56     if (argc>1)
    57       std::cout << "matrix_test -v : for printing extra information\n";
    58   }
    59 
    60   *error << "Testing matrix class" << std::endl;
    61   bool ok = true;
     53  test::Suite suite(argc, argv);
     54
     55  suite.err() << "Testing matrix class" << std::endl;
    6256  utility::Matrix unit3x3(3,3);
    6357  for (size_t i=0; i<unit3x3.rows(); ++i)
    6458    unit3x3(i,i)=1;
    6559
    66   *error << "\tcopy constructor and operator!=" << std::endl;
     60  suite.err() << "\tcopy constructor and operator!=" << std::endl;
    6761  utility::Matrix m(3,3,9);
    6862  utility::Matrix m2(m);
    6963  if (m2!=m)
    70     ok=false;
    71 
    72   *error << "\toutput operator and istream constructor" << std::endl;
     64    suite.add(false);
     65
     66  suite.err() << "\toutput operator and istream constructor" << std::endl;
    7367  // Checking that the matrix output operator writes a file that the
    7468  // input operator can read.
     
    8074  is.close();
    8175  if (m3!=m2)
    82     ok=false;
     76    suite.add(false);
    8377  std::remove("data/tmp_test_matrix.txt");
    8478
    85   *error << "\toperator*=(double)" << std::endl;
     79  suite.err() << "\toperator*=(double)" << std::endl;
    8680  utility::Matrix m4(3,3,1);
    8781  m4 *= 9;
    8882  if (m4!=m) {
    89     ok=false;
    90     *error << "error operator*=(double)" << std::endl;
     83    suite.add(false);
     84    suite.err() << "error operator*=(double)" << std::endl;
    9185  }
    9286
     
    10599  // a non-view matrix is copied
    106100  {
    107     *error << "\tcopy constructor" << std::endl;
     101    suite.err() << "\tcopy constructor" << std::endl;
    108102    utility::Matrix m2(m5);
    109     ok &= (m2.rows()==m5.rows());
    110     ok &= (m2.columns()==m5.columns());
    111     ok &= (m2==m5);
    112     ok &= (&m2 != &m5);
    113   }
    114 
    115   *error << "\tsub-(row)vector" << std::endl;
     103    suite.add(m2.rows()==m5.rows());
     104    suite.add(m2.columns()==m5.columns());
     105    suite.add(m2==m5);
     106    suite.add(&m2 != &m5);
     107  }
     108
     109  suite.err() << "\tsub-(row)vector" << std::endl;
    116110  // Checking that the row view works, i.e. mutation to the view are
    117111  // reflected in the viewed object.
     
    131125      m5_sum3+=m5(i,j);
    132126  if (m5_sum3-m5_sum2+v5subrow_sum>1e-13) {
    133     ok=false;
    134     *error << "error sub-vector test 1" << std::endl;
    135   }
    136 
    137   *error << "\tsub-(column)vector" << std::endl;
     127    suite.add(false);
     128    suite.err() << "error sub-vector test 1" << std::endl;
     129  }
     130
     131  suite.err() << "\tsub-(column)vector" << std::endl;
    138132  // Checking that the column view works, i.e. mutation to the view
    139133  // are reflected in the viewed object.
     
    153147      m5_sum4+=m5(i,j);
    154148  if (m5_sum4-m5_sum3-v5subcolumn.size()+v5subcolumn_sum>1e-13) {
    155     ok=false;
    156     *error << "error sub-vector test 2" << std::endl;
     149    suite.add(false);
     150    suite.err() << "error sub-vector test 2" << std::endl;
    157151  }
    158152
     
    163157    v5subrow_sum2+=v5subrow(i);
    164158  if (v5subrow_sum2-v5subcolumn(3)>1e-13) {
    165     ok=false;
    166     *error << "error sub-vector test 3" << std::endl;
    167   }
    168 
    169   *error << "\tsub-vector and vector copying" << std::endl;
     159    suite.add(false);
     160    suite.err() << "error sub-vector test 3" << std::endl;
     161  }
     162
     163  suite.err() << "\tsub-vector and vector copying" << std::endl;
    170164  // Checking that a view is not inherited through the copy
    171165  // contructor.
     
    176170    v5subrow_sum3+=v5subrow(i);
    177171  if (v5subrow_sum3-v5subrow_sum2>1e-13) {
    178     ok=false;
    179     *error << "error sub-vector test 4" << std::endl;
     172    suite.add(false);
     173    suite.err() << "error sub-vector test 4" << std::endl;
    180174  }
    181175  // Checking that values in a vector is copied into a viewed matrix.
     
    186180      m5_sum5+=m5(i,j);
    187181  if (m5_sum5-m5_sum4-v5subrow.size()*2+v5subrow_sum3>1e-13) {
    188     ok=false;
    189     *error << "error sub-vector test 5" << std::endl;
     182    suite.add(false);
     183    suite.err() << "error sub-vector test 5" << std::endl;
    190184  }
    191185
    192186  // Checking that the memberfunction matrixwrapper::row() returns a
    193187  // view
    194   *error << "\tthat class member returns a view" << std::endl;
     188  suite.err() << "\tthat class member returns a view" << std::endl;
    195189  matrixwrapper mw(5,2);
    196190  utility::VectorView mwrow=mw.row(2);
    197191  if (mwrow.gsl_vector_p()->data != &(mw.matrix()(2,0))) {
    198     ok=false;
    199     *error << "error sub-vector test 7" << std::endl;
    200   }
    201 
    202   *error << "\tmatrix::nan()" << std::endl;
     192    suite.add(false);
     193    suite.err() << "error sub-vector test 7" << std::endl;
     194  }
     195
     196  suite.err() << "\tmatrix::nan()" << std::endl;
    203197  is.open("data/sorlie_centroid_data.txt");
    204198  utility::Matrix* m_nan = new utility::Matrix(is,'\t');
     
    207201  is.close();
    208202  if (m_weight(0,0)!=1){
    209     *error << "error in matrix::nan(): element(0,0) is " << m_weight(0,0)
     203    suite.err() << "error in matrix::nan(): element(0,0) is " << m_weight(0,0)
    210204           << " expected 1." << std::endl;
    211     ok=false;
     205    suite.add(false);
    212206  }
    213207  if (m_weight(3,2)!=0){
    214     *error << "error in matrix::nan(): element(3,2) is " << m_weight(3,2)
     208    suite.err() << "error in matrix::nan(): element(3,2) is " << m_weight(3,2)
    215209           << " expected 0." << std::endl;
    216     ok=false;
     210    suite.add(false);
    217211  }
    218212  delete m_nan;
    219213
    220   *error << "\toperator*=(matrix&)" << std::endl;
     214  suite.err() << "\toperator*=(matrix&)" << std::endl;
    221215  utility::Matrix m6(unit3x3);
    222216  m6 *= m;
    223217  if (m6!=m) {
    224     ok=false;
    225     *error << "error operator*=(matrix) 1" << std::endl;
     218    suite.add(false);
     219    suite.err() << "error operator*=(matrix) 1" << std::endl;
    226220  }
    227221  m6 *= unit3x3;
    228222  if (m6!=m) {
    229     ok=false;
    230     *error << "error operator*=(matrix) 2" << std::endl;
     223    suite.add(false);
     224    suite.err() << "error operator*=(matrix) 2" << std::endl;
    231225  }
    232226  m6*= utility::Matrix(3,4,1.0);
     
    237231  m6*= unit3x3;
    238232
    239   if (error!=&std::cerr)
    240     delete error;
    241 
    242   return (ok ? 0 : -1);
     233  suite.return_value();
    243234}
Note: See TracChangeset for help on using the changeset viewer.