From 4ae4878d3ea12003bf0a12ebf3f8ba60f0734e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Wed, 5 Nov 2014 15:19:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0test=20=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Test/AlgorithmTest.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/TinySTL/Test/AlgorithmTest.cpp b/TinySTL/Test/AlgorithmTest.cpp index 149dd75..8b47152 100644 --- a/TinySTL/Test/AlgorithmTest.cpp +++ b/TinySTL/Test/AlgorithmTest.cpp @@ -23,10 +23,7 @@ bool myfunction2(int i, int j) { bool comp_case_insensitive(char c1, char c2) { return (std::tolower(c1) == std::tolower(c2)); } -bool myfunction3(int i, int j) { - return (i == j); -} -int main(){ +void testAlgorithm(){ //test fill vector myvector1(8); // myvector: 0 0 0 0 0 0 0 0 fill(myvector1.begin(), myvector1.begin() + 4, 5); // myvector: 5 5 5 5 0 0 0 0 @@ -175,7 +172,7 @@ int main(){ it8 = adjacent_find(v1.begin(), v1.end()); if (it8 != v1.end()) std::cout << "the first pair of repeated elements are: " << *it8 << '\n'; - it8 = adjacent_find(++it8, v1.end(), myfunction3); + it8 = adjacent_find(++it8, v1.end(), myfunction2); if (it8 != v1.end()) std::cout << "the second pair of repeated elements are: " << *it8 << '\n'; @@ -186,6 +183,18 @@ int main(){ vector myvector6(myints4, myints4 + 8); mycount = count(myvector6.begin(), myvector6.end(), 20); std::cout << "20 appears " << mycount << " times.\n"; - system("pause"); - return 0; + + //test mismatch + vector myvector7; + for (int i = 1; i<6; i++) myvector7.push_back(i * 10); // myvector: 10 20 30 40 50 + int myints5[] = { 10, 20, 80, 320, 1024 }; // myints: 10 20 80 320 1024 + pair::iterator, int*> mypair; + mypair = mismatch(myvector7.begin(), myvector7.end(), myints5); + std::cout << "First mismatching elements: " << *mypair.first; + std::cout << " and " << *mypair.second << '\n'; + ++mypair.first; ++mypair.second; + mypair = mismatch(mypair.first, myvector7.end(), mypair.second, myfunction2); + std::cout << "Second mismatching elements: " << *mypair.first; + std::cout << " and " << *mypair.second << '\n'; + } \ No newline at end of file