genericopenlibs/cppstdlib/stl/test/unit/reviter_test.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 11 Jun 2010 15:26:22 +0300
changeset 34 5fae379060a7
parent 31 ce057bb09d0b
child 45 4b03adbd26ca
permissions -rw-r--r--
Revision: 201023 Kit: 2010123

#include <vector>
#include <list>
#include <algorithm>

#include "cppunit/cppunit_proxy.h"

#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
using namespace std;
#endif

//
// TestCase class
//
class ReviterTest : public CPPUNIT_NS::TestCase
{
  CPPUNIT_TEST_SUITE(ReviterTest);
  CPPUNIT_TEST(reviter1);
  CPPUNIT_TEST(reviter2);
  CPPUNIT_TEST(revbit1);
  CPPUNIT_TEST_SUITE_END();

protected:
  void reviter1();
  void reviter2();
  void revbit1();
};

CPPUNIT_TEST_SUITE_REGISTRATION(ReviterTest);

//
// tests implementation
//
void ReviterTest::reviter1()
{
  int array [] = { 1, 5, 2, 3 };

  vector<int> v(array, array + 4);
  typedef vector<int>::reverse_iterator reviter;
  reviter r(v.rend());
  r--;

  CPPUNIT_ASSERT(*r-- == 1);
  CPPUNIT_ASSERT(*r-- == 5);
  CPPUNIT_ASSERT(*r-- == 2);
  CPPUNIT_ASSERT(*r == 3);
  CPPUNIT_ASSERT(r==v.rbegin());
}
void ReviterTest::reviter2()
{
  int array [] = { 1, 5, 2, 3 };

  vector<int> v(array, array + 4);
  vector<int>::reverse_iterator r;
  r = v.rbegin();
  CPPUNIT_ASSERT(*r++ == 3);
  CPPUNIT_ASSERT(*r++ == 2);
  CPPUNIT_ASSERT(*r++ == 5);
  CPPUNIT_ASSERT(*r++ == 1);
  CPPUNIT_ASSERT(r==v.rend());
}
void ReviterTest::revbit1()
{
  int array [] = { 1, 5, 2, 3 };

  list<int> v(array, array + 4);
  list<int>::reverse_iterator r(v.rbegin());
  CPPUNIT_ASSERT(*r++ == 3);
  CPPUNIT_ASSERT(*r++ == 2);
  CPPUNIT_ASSERT(*r++ == 5);
  CPPUNIT_ASSERT(*r++ == 1);
  CPPUNIT_ASSERT(r==v.rend());
}