Update contrib.
6 #include "cppunit/cppunit_proxy.h"
8 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
15 class MismatchTest : public CPPUNIT_NS::TestCase
17 CPPUNIT_TEST_SUITE(MismatchTest);
18 CPPUNIT_TEST(mismatch0);
19 CPPUNIT_TEST(mismatch1);
20 CPPUNIT_TEST(mismatch2);
21 CPPUNIT_TEST_SUITE_END();
29 CPPUNIT_TEST_SUITE_REGISTRATION(MismatchTest);
32 // tests implementation
34 bool str_equal(const char* a_, const char* b_)
36 return strcmp(a_, b_) == 0 ? 1 : 0;
38 void MismatchTest::mismatch0()
40 int n1[5] = { 1, 2, 3, 4, 5 };
41 int n2[5] = { 1, 2, 3, 4, 5 };
42 int n3[5] = { 1, 2, 3, 2, 1 };
44 pair <int*, int*> result = mismatch((int*)n1, (int*)n1 + 5, (int*)n2);
45 CPPUNIT_ASSERT(result.first ==(n1 + 5) && result.second ==(n2 + 5));
47 result = mismatch((int*)n1, (int*)n1 + 5, (int*)n3);
48 CPPUNIT_ASSERT(!(result.first ==(n1 + 5) && result.second ==(n3 + 5)));
49 CPPUNIT_ASSERT((result.first - n1)==3);
51 void MismatchTest::mismatch1()
53 typedef vector<int> IntVec;
55 __iota(v1.begin(), v1.end(), 0);
58 pair <IntVec::iterator, IntVec::iterator> result = mismatch(v1.begin(), v1.end(), v2.begin());
60 CPPUNIT_ASSERT(result.first == v1.end() && result.second == v2.end());
63 result = mismatch(v1.begin(), v1.end(), v2.begin());
64 CPPUNIT_ASSERT(!(result.first == v1.end() && result.second == v2.end()));
65 CPPUNIT_ASSERT((result.first - v1.begin())==5);
67 void MismatchTest::mismatch2()
69 const unsigned size = 5;
70 char const* n1[size] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
73 copy(n1, n1 + 5, (char const**)n2);
74 pair <char const**, char const**> result = mismatch((char const**)n1, (char const**)n1 + size, (char const**)n2, str_equal);
76 CPPUNIT_ASSERT(result.first == n1 + size && result.second == n2 + size);
79 result = mismatch((char const**)n1, (char const**)n1 + size, (char const**)n2, str_equal);
80 CPPUNIT_ASSERT(!(result.first == n2 + size && result.second == n2 + size));
81 CPPUNIT_ASSERT((result.first - n1)==2);