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

setunion_test.cpp
Go to the documentation of this file.
00001 #include <numeric>
00002 #include <string>
00003 #include <iterator>
00004 #include <vector>
00005 #include <algorithm>
00006 #include <functional>
00007 
00008 #include "iota.h"
00009 #include "cppunit/cppunit_proxy.h"
00010 
00011 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
00012 using namespace std;
00013 #endif
00014 
00015 //
00016 // TestCase class
00017 //
00018 class SetUnionTest : public CPPUNIT_NS::TestCase
00019 {
00020   CPPUNIT_TEST_SUITE(SetUnionTest);
00021   CPPUNIT_TEST(setunon0);
00022   CPPUNIT_TEST(setunon1);
00023   CPPUNIT_TEST(setunon2);
00024   CPPUNIT_TEST_SUITE_END();
00025 
00026 protected:
00027   void setunon0();
00028   void setunon1();
00029   void setunon2();
00030 };
00031 
00032 CPPUNIT_TEST_SUITE_REGISTRATION(SetUnionTest);
00033 
00034 //
00035 // tests implementation
00036 //
00037 void SetUnionTest::setunon0()
00038 {
00039   int v1[3] = { 13, 18, 23 };
00040   int v2[4] = { 10, 13, 17, 23 };
00041   int result[7] = { 0, 0, 0, 0, 0, 0, 0 };
00042 
00043   set_union((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result);
00044 
00045   CPPUNIT_ASSERT(result[0]==10);
00046   CPPUNIT_ASSERT(result[1]==13);
00047   CPPUNIT_ASSERT(result[2]==17);
00048   CPPUNIT_ASSERT(result[3]==18);
00049   CPPUNIT_ASSERT(result[4]==23);
00050   CPPUNIT_ASSERT(result[5]==0);
00051   CPPUNIT_ASSERT(result[6]==0);
00052 }
00053 
00054 void SetUnionTest::setunon1()
00055 {
00056   vector <int> v1(10);
00057   __iota(v1.begin(), v1.end(), 0);
00058   vector <int> v2(10);
00059   __iota(v2.begin(), v2.end(), 7);
00060 
00061   vector<int> diff;
00062   set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(diff));
00063   CPPUNIT_ASSERT( diff.size() == 17 );
00064   for (int i = 0; i < 17; ++i) {
00065     CPPUNIT_ASSERT( diff[i] == i );
00066   }
00067 }
00068 
00069 void SetUnionTest::setunon2()
00070 {
00071   const char* word1 = "ABCDEFGHIJKLMNO";
00072   const char* word2 = "LMNOPQRSTUVWXYZ";
00073 
00074   string diff;
00075   set_union(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2),
00076             back_inserter(diff), less<char>());
00077   CPPUNIT_ASSERT( diff.size() == 26 );
00078   for (int i = 0; i < 26; ++i) {
00079     CPPUNIT_ASSERT( diff[i] == ('A' + i) );
00080   }
00081 }

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