Home | History | Annotate | Download | only in unit
      1 #include <vector>
      2 #include <list>
      3 #include <algorithm>
      4 
      5 #include "cppunit/cppunit_proxy.h"
      6 
      7 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
      8 using namespace std;
      9 #endif
     10 
     11 //
     12 // TestCase class
     13 //
     14 class ReviterTest : public CPPUNIT_NS::TestCase
     15 {
     16   CPPUNIT_TEST_SUITE(ReviterTest);
     17   CPPUNIT_TEST(reviter1);
     18   CPPUNIT_TEST(reviter2);
     19   CPPUNIT_TEST(revbit1);
     20   CPPUNIT_TEST_SUITE_END();
     21 
     22 protected:
     23   void reviter1();
     24   void reviter2();
     25   void revbit1();
     26 };
     27 
     28 CPPUNIT_TEST_SUITE_REGISTRATION(ReviterTest);
     29 
     30 //
     31 // tests implementation
     32 //
     33 void ReviterTest::reviter1()
     34 {
     35   int array [] = { 1, 5, 2, 3 };
     36 
     37   vector<int> v(array, array + 4);
     38   typedef vector<int>::reverse_iterator reviter;
     39   reviter r(v.rend());
     40   r--;
     41 
     42   CPPUNIT_ASSERT(*r-- == 1);
     43   CPPUNIT_ASSERT(*r-- == 5);
     44   CPPUNIT_ASSERT(*r-- == 2);
     45   CPPUNIT_ASSERT(*r == 3);
     46   CPPUNIT_ASSERT(r==v.rbegin());
     47 }
     48 void ReviterTest::reviter2()
     49 {
     50   int array [] = { 1, 5, 2, 3 };
     51 
     52   vector<int> v(array, array + 4);
     53   vector<int>::reverse_iterator r;
     54   r = v.rbegin();
     55   CPPUNIT_ASSERT(*r++ == 3);
     56   CPPUNIT_ASSERT(*r++ == 2);
     57   CPPUNIT_ASSERT(*r++ == 5);
     58   CPPUNIT_ASSERT(*r++ == 1);
     59   CPPUNIT_ASSERT(r==v.rend());
     60 }
     61 void ReviterTest::revbit1()
     62 {
     63   int array [] = { 1, 5, 2, 3 };
     64 
     65   list<int> v(array, array + 4);
     66   list<int>::reverse_iterator r(v.rbegin());
     67   CPPUNIT_ASSERT(*r++ == 3);
     68   CPPUNIT_ASSERT(*r++ == 2);
     69   CPPUNIT_ASSERT(*r++ == 5);
     70   CPPUNIT_ASSERT(*r++ == 1);
     71   CPPUNIT_ASSERT(r==v.rend());
     72 }
     73