ReactOS  0.4.14-dev-554-g2f8d847
min_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 MinTest : public CPPUNIT_NS::TestCase
14 {
16  CPPUNIT_TEST(min1);
17  CPPUNIT_TEST(min2);
18  CPPUNIT_TEST(minelem1);
19  CPPUNIT_TEST(minelem2);
21 
22 protected:
23  void min1();
24  void min2();
25  void minelem1();
26  void minelem2();
27  static bool str_compare(const char* a_, const char* b_)
28  { return strcmp(a_, b_) < 0 ? 1 : 0; }
29 };
30 
32 
33 //
34 // tests implementation
35 //
37 {
38  int r = min(42, 100);
39  CPPUNIT_ASSERT( r == 42 );
40 
41  r = min(--r, r);
42  CPPUNIT_ASSERT( r == 41 );
43 }
45 {
46  const char* r = min((const char*)"shoe", (const char*)"shine", str_compare);
47  CPPUNIT_ASSERT(!strcmp(r, "shine"));
48 }
50 {
51  int numbers[6] = { -10, 15, -100, 36, -242, 42 };
52  int* r = min_element((int*)numbers, (int*)numbers + 6);
53  CPPUNIT_ASSERT(*r==-242);
54 }
56 {
57  const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
58 
59  const unsigned namesCt = sizeof(names) / sizeof(names[0]);
60  const char** r = min_element((const char**)names, (const char**)names + namesCt, str_compare);
61  CPPUNIT_ASSERT(!strcmp(*r, "Brett"));
62 }
CPPUNIT_TEST_SUITE_REGISTRATION(MinTest)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
void min1()
Definition: min_test.cpp:36
void min2()
Definition: min_test.cpp:44
_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last)
Definition: _algo.c:1828
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
GLuint GLuint * names
Definition: glext.h:11545
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
static bool str_compare(const char *a_, const char *b_)
Definition: min_test.cpp:27
void minelem2()
Definition: min_test.cpp:55
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
void minelem1()
Definition: min_test.cpp:49
#define min(a, b)
Definition: monoChain.cc:55
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469