ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

rotate_test.cpp
Go to the documentation of this file.
00001 #include <numeric>
00002 #include <vector>
00003 #include <algorithm>
00004 
00005 #include "iota.h"
00006 #include "cppunit/cppunit_proxy.h"
00007 
00008 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
00009 using namespace std;
00010 #endif
00011 
00012 //
00013 // TestCase class
00014 //
00015 class RotateTest : public CPPUNIT_NS::TestCase
00016 {
00017   CPPUNIT_TEST_SUITE(RotateTest);
00018   CPPUNIT_TEST(rotate0);
00019   CPPUNIT_TEST(rotate1);
00020   CPPUNIT_TEST(rotcopy0);
00021   CPPUNIT_TEST(rotcopy1);
00022   CPPUNIT_TEST_SUITE_END();
00023 
00024 protected:
00025   void rotate0();
00026   void rotate1();
00027   void rotcopy0();
00028   void rotcopy1();
00029 };
00030 
00031 CPPUNIT_TEST_SUITE_REGISTRATION(RotateTest);
00032 
00033 //
00034 // tests implementation
00035 //
00036 void RotateTest::rotate0()
00037 {
00038   int numbers[6] = { 0, 1, 2, 3, 4, 5 };
00039   // 3 4 5 0 1 2
00040   rotate((int*)numbers, numbers + 3, numbers + 6);
00041   CPPUNIT_ASSERT(numbers[0]==3);
00042   CPPUNIT_ASSERT(numbers[1]==4);
00043   CPPUNIT_ASSERT(numbers[2]==5);
00044   CPPUNIT_ASSERT(numbers[3]==0);
00045   CPPUNIT_ASSERT(numbers[4]==1);
00046   CPPUNIT_ASSERT(numbers[5]==2);
00047 }
00048 void RotateTest::rotate1()
00049 {
00050   vector <int> v1(10);
00051   __iota(v1.begin(), v1.end(), 0);
00052 
00053   rotate(v1.begin(), v1.begin()+1, v1.end());
00054   CPPUNIT_ASSERT(v1[0]==1);
00055   CPPUNIT_ASSERT(v1[1]==2);
00056   CPPUNIT_ASSERT(v1[2]==3);
00057   CPPUNIT_ASSERT(v1[3]==4);
00058   CPPUNIT_ASSERT(v1[4]==5);
00059   CPPUNIT_ASSERT(v1[5]==6);
00060   CPPUNIT_ASSERT(v1[6]==7);
00061   CPPUNIT_ASSERT(v1[7]==8);
00062   CPPUNIT_ASSERT(v1[8]==9);
00063   CPPUNIT_ASSERT(v1[9]==0);
00064 
00065   rotate(v1.begin(), v1.begin()+2, v1.end());
00066   CPPUNIT_ASSERT(v1[0]==3);
00067   CPPUNIT_ASSERT(v1[1]==4);
00068   CPPUNIT_ASSERT(v1[2]==5);
00069   CPPUNIT_ASSERT(v1[3]==6);
00070   CPPUNIT_ASSERT(v1[4]==7);
00071   CPPUNIT_ASSERT(v1[5]==8);
00072   CPPUNIT_ASSERT(v1[6]==9);
00073   CPPUNIT_ASSERT(v1[7]==0);
00074   CPPUNIT_ASSERT(v1[8]==1);
00075   CPPUNIT_ASSERT(v1[9]==2);
00076 
00077   rotate(v1.begin(), v1.begin()+7, v1.end());
00078   CPPUNIT_ASSERT(v1[0]==0);
00079   CPPUNIT_ASSERT(v1[1]==1);
00080   CPPUNIT_ASSERT(v1[2]==2);
00081   CPPUNIT_ASSERT(v1[3]==3);
00082   CPPUNIT_ASSERT(v1[4]==4);
00083   CPPUNIT_ASSERT(v1[5]==5);
00084   CPPUNIT_ASSERT(v1[6]==6);
00085   CPPUNIT_ASSERT(v1[7]==7);
00086   CPPUNIT_ASSERT(v1[8]==8);
00087   CPPUNIT_ASSERT(v1[9]==9);
00088 
00089 }
00090 void RotateTest::rotcopy0()
00091 {
00092   int numbers[6] = { 0, 1, 2, 3, 4, 5 };
00093 
00094   int result[6];
00095   rotate_copy((int*)numbers, (int*)numbers + 3, (int*)numbers + 6, (int*)result);
00096   // 3 4 5 0 1 2
00097   CPPUNIT_ASSERT(result[0]==3);
00098   CPPUNIT_ASSERT(result[1]==4);
00099   CPPUNIT_ASSERT(result[2]==5);
00100   CPPUNIT_ASSERT(result[3]==0);
00101   CPPUNIT_ASSERT(result[4]==1);
00102   CPPUNIT_ASSERT(result[5]==2);
00103 }
00104 void RotateTest::rotcopy1()
00105 {
00106   vector <int> v1(10);
00107   __iota(v1.begin(), v1.end(), 0);
00108   vector <int> v2(v1.size());
00109 
00110   rotate_copy(v1.begin(), v1.begin()+1, v1.end(), v2.begin());
00111   CPPUNIT_ASSERT(v2[0]==1);
00112   CPPUNIT_ASSERT(v2[1]==2);
00113   CPPUNIT_ASSERT(v2[2]==3);
00114   CPPUNIT_ASSERT(v2[3]==4);
00115   CPPUNIT_ASSERT(v2[4]==5);
00116   CPPUNIT_ASSERT(v2[5]==6);
00117   CPPUNIT_ASSERT(v2[6]==7);
00118   CPPUNIT_ASSERT(v2[7]==8);
00119   CPPUNIT_ASSERT(v2[8]==9);
00120   CPPUNIT_ASSERT(v2[9]==0);
00121 
00122   rotate_copy(v1.begin(), v1.begin()+3, v1.end(), v2.begin());
00123   CPPUNIT_ASSERT(v2[0]==3);
00124   CPPUNIT_ASSERT(v2[1]==4);
00125   CPPUNIT_ASSERT(v2[2]==5);
00126   CPPUNIT_ASSERT(v2[3]==6);
00127   CPPUNIT_ASSERT(v2[4]==7);
00128   CPPUNIT_ASSERT(v2[5]==8);
00129   CPPUNIT_ASSERT(v2[6]==9);
00130   CPPUNIT_ASSERT(v2[7]==0);
00131   CPPUNIT_ASSERT(v2[8]==1);
00132   CPPUNIT_ASSERT(v2[9]==2);
00133 }

Generated on Sat May 26 2012 04:34:42 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.