Ignore:
Timestamp:
Mar 21, 2009, 5:40:44 AM (14 years ago)
Author:
Peter
Message:

moving tests for iterator features from iterator_test.cc to class test::Suite so they can be utilized in several places.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/iterator_test.cc

    r1797 r1877  
    6060void test_boost_util(test::Suite&);
    6161
    62 template<typename TrivialIterator>
    63 void test_trivial_iterator(const TrivialIterator&, test::Suite&);
    64 
    65 template<typename InputIterator>
    66 void test_input_iterator(InputIterator&, test::Suite&);
    67 
    68 template<typename OutputIterator>
    69 void test_output_iterator(OutputIterator&, test::Suite&);
    70 
    71 template<typename ForwardIterator>
    72 void test_forward_iterator(ForwardIterator, test::Suite&);
    73 
    74 template<typename BidirectionalIterator>
    75 void test_bidirectional_iterator(BidirectionalIterator, test::Suite&);
    76 
    77 template<typename RandomAccessIterator>
    78 void test_random_access_iterator(RandomAccessIterator, test::Suite&);
    79 
    8062void test_stride_iterator(test::Suite& suite);
    8163void test_weighted_iterator(test::Suite& suite);
     
    11597  classifier::DataLookup1D lookup(vec);
    11698  utility::Vector::iterator begin=vec.begin();
    117   test_random_access_iterator(begin, suite);
     99  suite.test_random_access_iterator(begin);
    118100  // test iterator to const_iterator conversion
    119101  utility::Vector::const_iterator ci = vec.begin();
    120   test_random_access_iterator(ci, suite);
     102  suite.test_random_access_iterator(ci);
    121103  ci = begin;
    122104  if (begin!=ci)
     
    131113  classifier::DataLookup1D::const_iterator lbegin=lookup.begin();
    132114  classifier::DataLookup1D::const_iterator lend=lookup.end();
    133   test_random_access_iterator(lbegin, suite);
     115  suite.test_random_access_iterator(lbegin);
    134116 
    135117  suite.err() << "copy from DataLookup1D to Vector" << std::endl;
     
    162144  utility::DataIterator<classifier::DataLookupWeighted1D::const_iterator>
    163145    data_iter(aw2.begin());
    164   test_random_access_iterator(data_iter, suite);
    165   test_random_access_iterator(weight_iterator(aw2.begin()), suite);
     146  suite.test_random_access_iterator(data_iter);
     147  suite.test_random_access_iterator(weight_iterator(aw2.begin()));
    166148  suite.add(*data_iter == 1.0);
    167149  suite.add(*data_iterator(aw2.begin()) == 1.0);
     
    295277}
    296278
    297 template<typename TrivialIterator>
    298 void test_trivial_iterator(const TrivialIterator& iter, test::Suite& suite)
    299 {
    300   suite.err() << "  testing Trivial features" << std::endl;
    301   typename std::iterator_traits<TrivialIterator>::value_type tmp = *iter;
    302   suite.add(tmp==*iter);
    303 }
    304 
    305 template<typename InputIterator>
    306 void test_input_iterator(InputIterator& iter, test::Suite& suite)
    307 {
    308   test_trivial_iterator(iter, suite);
    309   suite.err() << "  testing Input features" << std::endl;
    310   // just to check compilation
    311   if (false) {
    312     ++iter;
    313     iter++;
    314   }
    315 }
    316 
    317 template<typename OutputIterator>
    318 void test_output_iterator(OutputIterator& iter, test::Suite& suite)
    319 {
    320   test_trivial_iterator(iter, suite);
    321   suite.err() << "  testing Output features" << std::endl;
    322 }
    323 
    324 template<typename ForwardIterator>
    325 void test_forward_iterator(ForwardIterator iter, test::Suite& suite)
    326 {
    327   test_output_iterator(iter, suite);
    328   test_input_iterator(iter, suite);
    329   suite.err() << "  testing Forward features" << std::endl;
    330 
    331   typename std::iterator_traits<ForwardIterator>::value_type tmp = *iter;
    332   // testing multiple traversing is possible and does not change the data
    333   ForwardIterator iter1 = iter;
    334   ++iter1;
    335   suite.add(iter!=iter1);
    336   ForwardIterator iter2 = iter;
    337   ++iter2;
    338   suite.add(tmp==*iter);
    339 
    340 }
    341 
    342 template<typename BidirectionalIterator>
    343 void test_bidirectional_iterator(BidirectionalIterator iter, test::Suite& suite)
    344 {
    345   test_forward_iterator(iter, suite);
    346   bool ok_cached = suite.ok();
    347   suite.err() << "  testing Bidirectional features" << std::endl;
    348   const BidirectionalIterator i = iter;
    349   BidirectionalIterator tmp = iter--;
    350   suite.add(tmp==i);
    351   ++iter;
    352   tmp = --iter;
    353   if (!suite.add(tmp==iter))
    354     suite.err() << "operator-- failed" << std::endl;
    355   suite.add(++tmp==i);
    356   if (ok_cached && !suite.ok())
    357     suite.err() << "failed" << std::endl;
    358 }
    359 
    360 template<typename RandomAccessIterator>
    361 void test_random_access_iterator(RandomAccessIterator iter, test::Suite& suite)
    362 {
    363   test_bidirectional_iterator(iter, suite);
    364   suite.err() << "  testing RandomAccess features" << std::endl;
    365   bool ok_cached = suite.ok();
    366   RandomAccessIterator iter2 = iter;
    367   iter2 += 1;
    368   iter2 -= 1;
    369   RandomAccessIterator& iter3 = (iter2 += 1);
    370   RandomAccessIterator& iter4 = (iter3 -= 1);
    371   if (!suite.add(iter2 == iter4))
    372     suite.err() << "operator-(int) failed" << std::endl;
    373   suite.add(++iter2 == iter3);
    374  
    375   RandomAccessIterator iter5 = iter + 0;
    376   RandomAccessIterator iter6 = 0 + iter;
    377   suite.add(iter6 == iter5);
    378 
    379   RandomAccessIterator iter7 = iter - 0;
    380   suite.add(iter7 == iter);
    381   suite.add(iter7 - iter == 0);
    382   suite.add(! (iter7<iter));
    383 
    384   typename RandomAccessIterator::value_type tmp = iter[0];
    385   typename RandomAccessIterator::value_type tmp2 = *iter;
    386   tmp = tmp; // avoid compiler warning
    387   if (!suite.add(tmp == tmp2))
    388     suite.err() << "operator[] failed" << std::endl;
    389   if (!suite.add(iter[0] == *iter))
    390     suite.err() << "operator[] failed" << std::endl;
    391   if (ok_cached && !suite.ok())
    392     suite.err() << "failed" << std::endl;
    393 }
    394 
    395279void test_stride_iterator(test::Suite& suite)
    396280{
     
    425309  utility::DataWeight tmp = *iter;
    426310
    427   test_bidirectional_iterator(iter, suite);
    428   test_random_access_iterator(iter, suite);
     311  suite.test_bidirectional_iterator(iter);
     312  suite.test_random_access_iterator(iter);
    429313  std::vector<double> data(vec.size());
    430314  std::vector<double> weight(vec.size());
     
    471355{
    472356  classifier::MatrixLookup ml(10, 10);
    473   test_random_access_iterator(ml.begin(), suite);
     357  suite.test_random_access_iterator(ml.begin());
    474358  std::vector<double> vec(ml.rows()*ml.columns());
    475359  std::copy(ml.begin(), ml.end(), vec.begin());
Note: See TracChangeset for help on using the changeset viewer.