From 0ff926ec234aa9ea4ed6874a56af6104a6bdceb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Mon, 22 Dec 2014 09:37:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Test/VectorTest.cpp | 47 +++++++++++++++++++++++++++++++++++-- TinySTL/Test/VectorTest.h | 4 ++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/TinySTL/Test/VectorTest.cpp b/TinySTL/Test/VectorTest.cpp index 2c69908..23e1f0f 100644 --- a/TinySTL/Test/VectorTest.cpp +++ b/TinySTL/Test/VectorTest.cpp @@ -37,13 +37,56 @@ namespace TinySTL{ auto v8 = std::move(v4); assert(TinySTL::Test::container_equal(v7, v8)); } + void testCase3(){ + tsVec v1, v2; + for (int i = 0; i != 100; ++i){ + v1.push_back(i); + v2.push_back(i); + } + + assert(v1 == v2); + assert(!(v1 != v2)); + } + void testCase4(){ + tsVec myvector; + for (int i = 1; i <= 5; i++) myvector.push_back(i); + + std::cout << "myvector contains:"; + for (tsVec::iterator it = myvector.begin(); it != myvector.end(); ++it) + std::cout << ' ' << *it; + std::cout << '\n'; + + std::cout << "myvector contains:"; + for (tsVec::const_iterator it = myvector.cbegin(); it != myvector.cend(); ++it) + std::cout << ' ' << *it; + std::cout << '\n'; + } + void testCase5(){ + tsVec myvector(5); // 5 default-constructed ints + int i = 0; + tsVec::reverse_iterator rit = myvector.rbegin(); + for (; rit != myvector.rend(); ++rit) + *rit = ++i; + + std::cout << "myvector contains:"; + for (tsVec::iterator it = myvector.begin(); it != myvector.end(); ++it) + std::cout << ' ' << *it; + std::cout << '\n'; + std::cout << "myvector contains(reverse order):"; + for (tsVec::reverse_iterator it = myvector.rbegin(); it != myvector.rend(); ++it) + std::cout << ' ' << *it; + std::cout << '\n'; + } } } using namespace TinySTL::VectorTest; int main(){ - testCase1(); - testCase2(); + //testCase1(); + //testCase2(); + //testCase3(); + //testCase4(); + //testCase5(); system("pause"); return 0; } \ No newline at end of file diff --git a/TinySTL/Test/VectorTest.h b/TinySTL/Test/VectorTest.h index 2fea093..a2f9aee 100644 --- a/TinySTL/Test/VectorTest.h +++ b/TinySTL/Test/VectorTest.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -21,6 +22,9 @@ namespace TinySTL{ namespace VectorTest{ void testCase1(); void testCase2(); + void testCase3(); + void testCase4(); + void testCase5(); } }