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

multiset_test.cpp
Go to the documentation of this file.
00001 #include <set>
00002 #include <functional>
00003 
00004 #include "cppunit/cppunit_proxy.h"
00005 
00006 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
00007 using namespace std;
00008 #endif
00009 
00010 //
00011 // TestCase class
00012 //
00013 class MultisetTest : public CPPUNIT_NS::TestCase
00014 {
00015   typedef multiset<int, less<int> > mset;
00016 
00017   CPPUNIT_TEST_SUITE(MultisetTest);
00018   CPPUNIT_TEST(mset1);
00019   CPPUNIT_TEST(mset3);
00020   CPPUNIT_TEST(mset5);
00021   CPPUNIT_TEST_SUITE_END();
00022 
00023 protected:
00024   void mset1();
00025   void mset3();
00026   void mset5();
00027 
00028   static bool less_than(int a_, int b_)
00029   {
00030     return a_ < b_;
00031   }
00032 
00033   static bool greater_than(int a_, int b_)
00034   {
00035     return a_ > b_;
00036   }
00037 };
00038 
00039 CPPUNIT_TEST_SUITE_REGISTRATION(MultisetTest);
00040 
00041 //
00042 // tests implementation
00043 //
00044 void MultisetTest::mset1()
00045 {
00046   mset s;
00047   CPPUNIT_ASSERT(s.count(42) == 0);
00048   s.insert(42);
00049   CPPUNIT_ASSERT(s.count(42) == 1);
00050   s.insert(42);
00051   CPPUNIT_ASSERT(s.count(42) == 2);
00052 
00053   mset::iterator i = s.find(40);
00054   CPPUNIT_ASSERT(i == s.end());
00055 
00056   i = s.find(42);
00057   CPPUNIT_ASSERT(i != s.end());
00058   size_t count = s.erase(42);
00059   CPPUNIT_ASSERT(count == 2);
00060 }
00061 void MultisetTest::mset3()
00062 {
00063   int array [] = { 3, 6, 1, 2, 3, 2, 6, 7, 9 };
00064 
00065   //Check iterator on a mutable set
00066   mset s(array, array + 9);
00067   mset::iterator i;
00068   i = s.lower_bound(3);
00069   CPPUNIT_ASSERT(*i == 3);
00070   i = s.upper_bound(3);
00071   CPPUNIT_ASSERT(*i == 6);
00072   pair<mset::iterator, mset::iterator> p = s.equal_range(5);
00073   CPPUNIT_ASSERT(*(p.first) == 6);
00074   CPPUNIT_ASSERT(*(p.second) == 6);
00075 
00076   //Check const_iterator on a mutable multiset
00077   mset::const_iterator ci;
00078   ci = s.lower_bound(3);
00079   CPPUNIT_ASSERT(*ci == 3);
00080   ci = s.upper_bound(3);
00081   CPPUNIT_ASSERT(*ci == 6);
00082   pair<mset::const_iterator, mset::const_iterator> cp;
00083 #ifdef _STLP_MEMBER_TEMPLATES
00084   cp = s.equal_range(5);
00085   CPPUNIT_ASSERT(*(cp.first) == 6);
00086   CPPUNIT_ASSERT(*(cp.second) == 6);
00087 #endif
00088 
00089   //Check const_iterator on a const multiset
00090   mset const& crs = s;
00091   ci = crs.lower_bound(3);
00092   CPPUNIT_ASSERT(*ci == 3);
00093   ci = crs.upper_bound(3);
00094   CPPUNIT_ASSERT(*ci == 6);
00095   cp = crs.equal_range(5);
00096   CPPUNIT_ASSERT(*(cp.first) == 6);
00097   CPPUNIT_ASSERT(*(cp.second) == 6);
00098 }
00099 void MultisetTest::mset5()
00100 {
00101   int array [] = { 3, 6, 1, 9 };
00102   int j;
00103 
00104   typedef pointer_to_binary_function<int, int, bool> fn_type;
00105   typedef multiset<int, fn_type, allocator<int> > fn_mset;
00106 
00107   fn_type f(less_than);
00108   fn_mset s1(array+0, array + 4 , f );
00109   fn_mset::const_iterator i = s1.begin();
00110   for (j = 0; i != s1.end(); ++i, ++j) {
00111     CPPUNIT_ASSERT(j != 0 || *i == 1);
00112     CPPUNIT_ASSERT(j != 1 || *i == 3);
00113     CPPUNIT_ASSERT(j != 2 || *i == 6);
00114     CPPUNIT_ASSERT(j != 3 || *i == 9);
00115   }
00116 
00117   fn_type g(greater_than);
00118   fn_mset s2(array, array + 4, g);
00119   i = s2.begin();
00120   for (j = 0; i != s2.end(); ++i, ++j) {
00121     CPPUNIT_ASSERT(j != 0 || *i == 9);
00122     CPPUNIT_ASSERT(j != 1 || *i == 6);
00123     CPPUNIT_ASSERT(j != 2 || *i == 3);
00124     CPPUNIT_ASSERT(j != 3 || *i == 1);
00125   }
00126 
00127 }

Generated on Sat May 26 2012 04:34:22 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.