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

merge_test.cpp
Go to the documentation of this file.
00001 #include <vector>
00002 #include <algorithm>
00003 #include <functional>
00004 #include <numeric>
00005 
00006 #include "iota.h"
00007 #include "cppunit/cppunit_proxy.h"
00008 
00009 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
00010 using namespace std;
00011 #endif
00012 
00013 //
00014 // TestCase class
00015 //
00016 class MergeTest : public CPPUNIT_NS::TestCase
00017 {
00018   CPPUNIT_TEST_SUITE(MergeTest);
00019   CPPUNIT_TEST(merge0);
00020   CPPUNIT_TEST(merge1);
00021   CPPUNIT_TEST(merge2);
00022   CPPUNIT_TEST_SUITE_END();
00023 
00024 protected:
00025   void merge0();
00026   void merge1();
00027   void merge2();
00028 };
00029 
00030 CPPUNIT_TEST_SUITE_REGISTRATION(MergeTest);
00031 
00032 //
00033 // tests implementation
00034 //
00035 void MergeTest::merge0()
00036 {
00037   int numbers1[5] = { 1, 6, 13, 25, 101 };
00038   int numbers2[5] = {-5, 26, 36, 46, 99 };
00039 
00040   int result[10];
00041   merge((int*)numbers1, (int*)numbers1 + 5, (int*)numbers2, (int*)numbers2 + 5, (int*)result);
00042 
00043   CPPUNIT_ASSERT(result[0]==-5);
00044   CPPUNIT_ASSERT(result[1]==1);
00045   CPPUNIT_ASSERT(result[2]==6);
00046   CPPUNIT_ASSERT(result[3]==13);
00047   CPPUNIT_ASSERT(result[4]==25);
00048   CPPUNIT_ASSERT(result[5]==26);
00049   CPPUNIT_ASSERT(result[6]==36);
00050   CPPUNIT_ASSERT(result[7]==46);
00051   CPPUNIT_ASSERT(result[8]==99);
00052   CPPUNIT_ASSERT(result[9]==101);
00053 }
00054 void MergeTest::merge1()
00055 {
00056   vector<int> v1(5);
00057   vector<int> v2(v1.size());
00058   __iota(v1.begin(), v1.end(), 0);
00059   __iota(v2.begin(), v2.end(), 3);
00060 
00061   vector <int> result(v1.size() + v2.size());
00062   merge(v1.begin(), v1.end(), v2.begin(), v2.end(), result.begin());
00063 
00064   CPPUNIT_ASSERT(result[0]==0);
00065   CPPUNIT_ASSERT(result[1]==1);
00066   CPPUNIT_ASSERT(result[2]==2);
00067   CPPUNIT_ASSERT(result[3]==3);
00068   CPPUNIT_ASSERT(result[4]==3);
00069   CPPUNIT_ASSERT(result[5]==4);
00070   CPPUNIT_ASSERT(result[6]==4);
00071   CPPUNIT_ASSERT(result[7]==5);
00072   CPPUNIT_ASSERT(result[8]==6);
00073   CPPUNIT_ASSERT(result[9]==7);
00074 
00075 }
00076 void MergeTest::merge2()
00077 {
00078   vector <int> v1(5);
00079   vector <int> v2(v1.size());
00080   for (int i = 0; (size_t)i < v1.size(); ++i) {
00081     v1[i] = 10 - i;
00082     v2[i] =  7 - i;
00083   }
00084   vector<int> result(v1.size() + v2.size());
00085   merge(v1.begin(), v1.end(), v2.begin(), v2.end(), result.begin(), greater<int>() );
00086 
00087   CPPUNIT_ASSERT(result[0]==10);
00088   CPPUNIT_ASSERT(result[1]==9);
00089   CPPUNIT_ASSERT(result[2]==8);
00090   CPPUNIT_ASSERT(result[3]==7);
00091   CPPUNIT_ASSERT(result[4]==7);
00092   CPPUNIT_ASSERT(result[5]==6);
00093   CPPUNIT_ASSERT(result[6]==6);
00094   CPPUNIT_ASSERT(result[7]==5);
00095   CPPUNIT_ASSERT(result[8]==4);
00096   CPPUNIT_ASSERT(result[9]==3);
00097 }

Generated on Sun May 27 2012 04:35:29 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.