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

bound_test.cpp
Go to the documentation of this file.
00001 #include <vector>
00002 #include <algorithm>
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 BoundTest : public CPPUNIT_NS::TestCase
00014 {
00015   CPPUNIT_TEST_SUITE(BoundTest);
00016   CPPUNIT_TEST(lwrbnd1);
00017   CPPUNIT_TEST(lwrbnd2);
00018   CPPUNIT_TEST(uprbnd1);
00019   CPPUNIT_TEST(uprbnd2);
00020   CPPUNIT_TEST_SUITE_END();
00021 
00022 protected:
00023   void lwrbnd1();
00024   void lwrbnd2();
00025   void uprbnd1();
00026   void uprbnd2();
00027 
00028   static bool char_str_less(const char* a_, const char* b_)
00029   {
00030     return strcmp(a_, b_) < 0 ? 1 : 0;
00031   }
00032 };
00033 
00034 CPPUNIT_TEST_SUITE_REGISTRATION(BoundTest);
00035 
00036 //
00037 // tests implementation
00038 //
00039 void BoundTest::uprbnd1()
00040 {
00041   int arr[20];
00042   for(int i = 0; i < 20; i++)
00043   {
00044     arr[i] = i/4;
00045   }
00046   int location = upper_bound((int*)arr, (int*)arr + 20, 3) - arr;
00047   CPPUNIT_ASSERT(location==16);
00048 }
00049 
00050 void BoundTest::uprbnd2()
00051 {
00052   char const* str [] = { "a", "a", "b", "b", "q", "w", "z" };
00053 
00054   const unsigned strCt = sizeof(str)/sizeof(str[0]);
00055 
00056   int location = (upper_bound((char const**)str,  (char const**)str + strCt, (const char *)"d", char_str_less) - str);
00057   CPPUNIT_ASSERT(location==4);
00058 }
00059 void BoundTest::lwrbnd1()
00060 {
00061   vector <int> v1(20);
00062   for (int i = 0; (size_t)i < v1.size(); ++i)
00063   {
00064     v1[i] = i/4;
00065   }
00066   // 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
00067   vector<int>::iterator location = lower_bound(v1.begin(), v1.end(), 3);
00068 
00069   CPPUNIT_ASSERT((location - v1.begin())==12);
00070 }
00071 
00072 void BoundTest::lwrbnd2()
00073 {
00074   char const* str [] = { "a", "a", "b", "b", "q", "w", "z" };
00075 
00076   const unsigned strCt = sizeof(str)/sizeof(str[0]);
00077   char const** location = lower_bound((char const**)str,  (char const**)str + strCt, (const char *)"d", char_str_less);
00078 
00079   CPPUNIT_ASSERT((location - str) == 4);
00080 }

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