Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensearch_test.cpp
Go to the documentation of this file.
00001 #include <vector> 00002 #include <numeric> 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 SearchTest : public CPPUNIT_NS::TestCase 00016 { 00017 CPPUNIT_TEST_SUITE(SearchTest); 00018 CPPUNIT_TEST(search0); 00019 CPPUNIT_TEST(search1); 00020 CPPUNIT_TEST(search2); 00021 CPPUNIT_TEST_SUITE_END(); 00022 00023 protected: 00024 void search0(); 00025 void search1(); 00026 void search2(); 00027 00028 static bool str_equal(const char* a_, const char* b_) 00029 { 00030 return strcmp(a_, b_) == 0 ? 1 : 0; 00031 } 00032 }; 00033 00034 CPPUNIT_TEST_SUITE_REGISTRATION(SearchTest); 00035 00036 // 00037 // tests implementation 00038 // 00039 void SearchTest::search0() 00040 { 00041 int v1[6] = { 1, 1, 2, 3, 5, 8 }; 00042 int v2[6] = { 0, 1, 2, 3, 4, 5 }; 00043 int v3[2] = { 3, 4 }; 00044 00045 int* location; 00046 location = search((int*)v1, (int*)v1 + 6, (int*)v3, (int*)v3 + 2); 00047 CPPUNIT_ASSERT(location == v1 + 6); 00048 00049 location = search((int*)v2, (int*)v2 + 6, (int*)v3, (int*)v3 + 2); 00050 CPPUNIT_ASSERT(location != v2 + 6); 00051 CPPUNIT_ASSERT(location - v2 == 3); 00052 } 00053 void SearchTest::search1() 00054 { 00055 typedef vector <int> IntVec; 00056 IntVec v1(10); 00057 __iota(v1.begin(), v1.end(), 0); 00058 IntVec v2(3); 00059 __iota(v2.begin(), v2.end(), 50); 00060 00061 IntVec::iterator location; 00062 location = search(v1.begin(), v1.end(), v2.begin(), v2.end()); 00063 00064 CPPUNIT_ASSERT(location == v1.end()); 00065 00066 __iota(v2.begin(), v2.end(), 4); 00067 00068 location = search(v1.begin(), v1.end(), v2.begin(), v2.end()); 00069 00070 CPPUNIT_ASSERT(location != v1.end()); 00071 CPPUNIT_ASSERT(location - v1.begin() == 4); 00072 } 00073 void SearchTest::search2() 00074 { 00075 char const* grades[] = { "A", "B", "C", "D", "F" }; 00076 char const* letters[] = { "Q", "E", "D" }; 00077 const unsigned gradeCount = sizeof(grades) / sizeof(grades[0]); 00078 const unsigned letterCount = sizeof(letters) / sizeof(letters[0]); 00079 char const** location = search((char const**)grades, (char const**)grades + gradeCount, (char const**)letters, (char const**)letters + letterCount, str_equal); 00080 00081 CPPUNIT_ASSERT(location == grades + gradeCount); 00082 00083 copy((char const**)grades + 1, (char const**)grades + 1 + letterCount, (char const**)letters); 00084 location = search((char const**)grades, (char const**)grades + gradeCount, (char const**)letters, (char const**)letters + letterCount, str_equal); 00085 00086 CPPUNIT_ASSERT(location != grades + gradeCount); 00087 CPPUNIT_ASSERT(location - grades == 1); 00088 00089 } Generated on Sun May 27 2012 04:35:44 for ReactOS by
1.7.6.1
|