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

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

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.