Update contrib.
6 #include "cppunit/cppunit_proxy.h"
8 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
15 class SearchTest : public CPPUNIT_NS::TestCase
17 CPPUNIT_TEST_SUITE(SearchTest);
18 CPPUNIT_TEST(search0);
19 CPPUNIT_TEST(search1);
20 CPPUNIT_TEST(search2);
21 CPPUNIT_TEST_SUITE_END();
28 static bool str_equal(const char* a_, const char* b_)
30 return strcmp(a_, b_) == 0 ? 1 : 0;
34 CPPUNIT_TEST_SUITE_REGISTRATION(SearchTest);
37 // tests implementation
39 void SearchTest::search0()
41 int v1[6] = { 1, 1, 2, 3, 5, 8 };
42 int v2[6] = { 0, 1, 2, 3, 4, 5 };
46 location = search((int*)v1, (int*)v1 + 6, (int*)v3, (int*)v3 + 2);
47 CPPUNIT_ASSERT(location == v1 + 6);
49 location = search((int*)v2, (int*)v2 + 6, (int*)v3, (int*)v3 + 2);
50 CPPUNIT_ASSERT(location != v2 + 6);
51 CPPUNIT_ASSERT(location - v2 == 3);
53 void SearchTest::search1()
55 typedef vector <int> IntVec;
57 __iota(v1.begin(), v1.end(), 0);
59 __iota(v2.begin(), v2.end(), 50);
61 IntVec::iterator location;
62 location = search(v1.begin(), v1.end(), v2.begin(), v2.end());
64 CPPUNIT_ASSERT(location == v1.end());
66 __iota(v2.begin(), v2.end(), 4);
68 location = search(v1.begin(), v1.end(), v2.begin(), v2.end());
70 CPPUNIT_ASSERT(location != v1.end());
71 CPPUNIT_ASSERT(location - v1.begin() == 4);
73 void SearchTest::search2()
75 char const* grades[] = { "A", "B", "C", "D", "F" };
76 char const* letters[] = { "Q", "E", "D" };
77 const unsigned gradeCount = sizeof(grades) / sizeof(grades[0]);
78 const unsigned letterCount = sizeof(letters) / sizeof(letters[0]);
79 char const** location = search((char const**)grades, (char const**)grades + gradeCount, (char const**)letters, (char const**)letters + letterCount, str_equal);
81 CPPUNIT_ASSERT(location == grades + gradeCount);
83 copy((char const**)grades + 1, (char const**)grades + 1 + letterCount, (char const**)letters);
84 location = search((char const**)grades, (char const**)grades + gradeCount, (char const**)letters, (char const**)letters + letterCount, str_equal);
86 CPPUNIT_ASSERT(location != grades + gradeCount);
87 CPPUNIT_ASSERT(location - grades == 1);