ReactOS  0.4.13-dev-100-gc8611ae
max_test.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <algorithm>
3 
5 
6 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
7 using namespace std;
8 #endif
9 
10 //
11 // TestCase class
12 //
13 class MaxTest : public CPPUNIT_NS::TestCase
14 {
16  CPPUNIT_TEST(max1);
17  CPPUNIT_TEST(max2);
18  CPPUNIT_TEST(maxelem1);
19  CPPUNIT_TEST(maxelem2);
21 
22 protected:
23  void max1();
24  void max2();
25  void maxelem1();
26  void maxelem2();
27 
28  static bool str_compare(const char* a_, const char* b_)
29  { return strcmp(a_, b_) < 0 ? 1 : 0; }
30 };
31 
33 
34 //
35 // tests implementation
36 //
38 {
39  int r = max(42, 100);
40  CPPUNIT_ASSERT( r == 100 );
41 
42  int t = max(++r, 0);
43  CPPUNIT_ASSERT( t == 101 );
44 }
46 {
47  const char* r = max((const char*)"shoe", (const char*)"shine", str_compare);
48  CPPUNIT_ASSERT(!strcmp(r, "shoe"));
49 }
51 {
52  int numbers[6] = { 4, 10, 56, 11, -42, 19 };
53 
54  int* r = max_element((int*)numbers, (int*)numbers + 6);
55  CPPUNIT_ASSERT(*r==56);
56 }
58 {
59  const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
60 
61  const unsigned namesCt = sizeof(names) / sizeof(names[0]);
62  const char** r = max_element((const char**)names, (const char**)names + namesCt, str_compare);
63  CPPUNIT_ASSERT(!strcmp(*r, "Todd"));
64 }
#define max(a, b)
Definition: svc.c:63
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
static bool str_compare(const char *a_, const char *b_)
Definition: max_test.cpp:28
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
GLuint GLuint * names
Definition: glext.h:11545
void max2()
Definition: max_test.cpp:45
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last)
Definition: _algo.c:1800
void maxelem2()
Definition: max_test.cpp:57
void max1()
Definition: max_test.cpp:37
CPPUNIT_TEST_SUITE_REGISTRATION(MaxTest)
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
void maxelem1()
Definition: max_test.cpp:50