Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmismatch_test.cpp
Go to the documentation of this file.
00001 #include <numeric> 00002 #include <vector> 00003 #include <algorithm> 00004 00005 #include "iota.h" 00006 #include "cppunit/cppunit_proxy.h" 00007 00008 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 00009 using namespace std; 00010 #endif 00011 00012 // 00013 // TestCase class 00014 // 00015 class MismatchTest : public CPPUNIT_NS::TestCase 00016 { 00017 CPPUNIT_TEST_SUITE(MismatchTest); 00018 CPPUNIT_TEST(mismatch0); 00019 CPPUNIT_TEST(mismatch1); 00020 CPPUNIT_TEST(mismatch2); 00021 CPPUNIT_TEST_SUITE_END(); 00022 00023 protected: 00024 void mismatch0(); 00025 void mismatch1(); 00026 void mismatch2(); 00027 }; 00028 00029 CPPUNIT_TEST_SUITE_REGISTRATION(MismatchTest); 00030 00031 // 00032 // tests implementation 00033 // 00034 bool str_equal(const char* a_, const char* b_) 00035 { 00036 return strcmp(a_, b_) == 0 ? 1 : 0; 00037 } 00038 void MismatchTest::mismatch0() 00039 { 00040 int n1[5] = { 1, 2, 3, 4, 5 }; 00041 int n2[5] = { 1, 2, 3, 4, 5 }; 00042 int n3[5] = { 1, 2, 3, 2, 1 }; 00043 00044 pair <int*, int*> result = mismatch((int*)n1, (int*)n1 + 5, (int*)n2); 00045 CPPUNIT_ASSERT(result.first ==(n1 + 5) && result.second ==(n2 + 5)); 00046 00047 result = mismatch((int*)n1, (int*)n1 + 5, (int*)n3); 00048 CPPUNIT_ASSERT(!(result.first ==(n1 + 5) && result.second ==(n3 + 5))); 00049 CPPUNIT_ASSERT((result.first - n1)==3); 00050 } 00051 void MismatchTest::mismatch1() 00052 { 00053 typedef vector<int> IntVec; 00054 IntVec v1(10); 00055 __iota(v1.begin(), v1.end(), 0); 00056 IntVec v2(v1); 00057 00058 pair <IntVec::iterator, IntVec::iterator> result = mismatch(v1.begin(), v1.end(), v2.begin()); 00059 00060 CPPUNIT_ASSERT(result.first == v1.end() && result.second == v2.end()); 00061 00062 v2[v2.size()/2] = 42; 00063 result = mismatch(v1.begin(), v1.end(), v2.begin()); 00064 CPPUNIT_ASSERT(!(result.first == v1.end() && result.second == v2.end())); 00065 CPPUNIT_ASSERT((result.first - v1.begin())==5); 00066 } 00067 void MismatchTest::mismatch2() 00068 { 00069 const unsigned size = 5; 00070 char const* n1[size] = { "Brett", "Graham", "Jack", "Mike", "Todd" }; 00071 00072 char const* n2[size]; 00073 copy(n1, n1 + 5, (char const**)n2); 00074 pair <char const**, char const**> result = mismatch((char const**)n1, (char const**)n1 + size, (char const**)n2, str_equal); 00075 00076 CPPUNIT_ASSERT(result.first == n1 + size && result.second == n2 + size); 00077 00078 n2[2] = "QED"; 00079 result = mismatch((char const**)n1, (char const**)n1 + size, (char const**)n2, str_equal); 00080 CPPUNIT_ASSERT(!(result.first == n2 + size && result.second == n2 + size)); 00081 CPPUNIT_ASSERT((result.first - n1)==2); 00082 } Generated on Mon May 28 2012 04:35:19 for ReactOS by
1.7.6.1
|