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

min_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 MinTest : public CPPUNIT_NS::TestCase
00014 {
00015   CPPUNIT_TEST_SUITE(MinTest);
00016   CPPUNIT_TEST(min1);
00017   CPPUNIT_TEST(min2);
00018   CPPUNIT_TEST(minelem1);
00019   CPPUNIT_TEST(minelem2);
00020   CPPUNIT_TEST_SUITE_END();
00021 
00022 protected:
00023   void min1();
00024   void min2();
00025   void minelem1();
00026   void minelem2();
00027   static bool str_compare(const char* a_, const char* b_)
00028   { return strcmp(a_, b_) < 0 ? 1 : 0; }
00029 };
00030 
00031 CPPUNIT_TEST_SUITE_REGISTRATION(MinTest);
00032 
00033 //
00034 // tests implementation
00035 //
00036 void MinTest::min1()
00037 {
00038   int r = min(42, 100);
00039   CPPUNIT_ASSERT( r == 42 );
00040 
00041   r = min(--r, r);
00042   CPPUNIT_ASSERT( r == 41 );
00043 }
00044 void MinTest::min2()
00045 {
00046   const char* r = min((const char*)"shoe", (const char*)"shine", str_compare);
00047   CPPUNIT_ASSERT(!strcmp(r, "shine"));
00048 }
00049 void MinTest::minelem1()
00050 {
00051   int numbers[6] = { -10, 15, -100, 36, -242, 42 };
00052   int* r = min_element((int*)numbers, (int*)numbers + 6);
00053   CPPUNIT_ASSERT(*r==-242);
00054 }
00055 void MinTest::minelem2()
00056 {
00057   const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
00058 
00059   const unsigned namesCt = sizeof(names) / sizeof(names[0]);
00060   const char** r = min_element((const char**)names, (const char**)names + namesCt, str_compare);
00061   CPPUNIT_ASSERT(!strcmp(*r, "Brett"));
00062 }

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.