First public contribution.
4 #include "cppunit/cppunit_proxy.h"
6 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
13 class MaxTest : public CPPUNIT_NS::TestCase
15 CPPUNIT_TEST_SUITE(MaxTest);
18 CPPUNIT_TEST(maxelem1);
19 CPPUNIT_TEST(maxelem2);
20 CPPUNIT_TEST_SUITE_END();
28 static bool str_compare(const char* a_, const char* b_)
29 { return strcmp(a_, b_) < 0 ? 1 : 0; }
32 CPPUNIT_TEST_SUITE_REGISTRATION(MaxTest);
35 // tests implementation
40 CPPUNIT_ASSERT( r == 100 );
43 CPPUNIT_ASSERT( r == 101 );
47 const char* r = max((const char*)"shoe", (const char*)"shine", str_compare);
48 CPPUNIT_ASSERT(!strcmp(r, "shoe"));
50 void MaxTest::maxelem1()
52 int numbers[6] = { 4, 10, 56, 11, -42, 19 };
54 int* r = max_element((int*)numbers, (int*)numbers + 6);
55 CPPUNIT_ASSERT(*r==56);
57 void MaxTest::maxelem2()
59 const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
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"));