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

bsearch_test.cpp
Go to the documentation of this file.
00001 #include <algorithm>
00002 
00003 #include "cppunit/cppunit_proxy.h"
00004 
00005 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
00006 using namespace std;
00007 #endif
00008 
00009 //
00010 // TestCase class
00011 //
00012 class BsearchTest : public CPPUNIT_NS::TestCase
00013 {
00014   CPPUNIT_TEST_SUITE(BsearchTest);
00015   CPPUNIT_TEST(bsearch1);
00016   CPPUNIT_TEST(bsearch2);
00017   CPPUNIT_TEST_SUITE_END();
00018 
00019 protected:
00020   void bsearch1();
00021   void bsearch2();
00022   static bool str_compare(const char* a_, const char* b_);
00023 };
00024 
00025 CPPUNIT_TEST_SUITE_REGISTRATION(BsearchTest);
00026 
00027 //
00028 // tests implementation
00029 //
00030 void BsearchTest::bsearch1()
00031 {
00032   int vector[100];
00033   for(int i = 0; i < 100; i++)
00034     vector[i] = i;
00035   CPPUNIT_ASSERT(binary_search(vector, vector + 100, 42));
00036 }
00037 
00038 void BsearchTest::bsearch2()
00039 {
00040   char const* labels[] = { "aa", "dd", "ff", "jj", "ss", "zz" };
00041   const unsigned count = sizeof(labels) / sizeof(labels[0]);
00042   // DEC C++ generates incorrect template instatiation code
00043   // for "ff" so must cast
00044   CPPUNIT_ASSERT(binary_search(labels, labels + count, (const char *)"ff", str_compare));
00045 }
00046 bool BsearchTest::str_compare(const char* a_, const char* b_)
00047 {
00048   return strcmp(a_, b_) < 0 ? 1 : 0;
00049 }

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.