From 32e37b4977067dda2fc5355a5ab51f85a2ff433a 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:48:33 +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 | 46 +++++++++++++++++++++++++++++++++++++ TinySTL/Test/VectorTest.h | 4 ++++ 2 files changed, 50 insertions(+) diff --git a/TinySTL/Test/VectorTest.cpp b/TinySTL/Test/VectorTest.cpp index 23e1f0f..9dab7b5 100644 --- a/TinySTL/Test/VectorTest.cpp +++ b/TinySTL/Test/VectorTest.cpp @@ -77,6 +77,48 @@ namespace TinySTL{ std::cout << ' ' << *it; std::cout << '\n'; } + void testCase6(){ + tsVec v(11, 0); + assert(v.size() == 11); + + v.resize(5); + assert(v.size() == 5); + + v.resize(20); + assert(v.size() == 20); + } + void testCase7(){ + tsVec v; + v.reserve(20); + assert(v.capacity() == 20); + } + void testCase8(){ + stdVec v1(10); + tsVec v2(10); + for (unsigned i = 0; i < 10; i++){ + v1[i] = i; + v2[i] = i; + } + assert(TinySTL::Test::container_equal(v1, v2)); + + v1.front() = 99; + v2.front() = 99; + v1.back() = 100; + v2.back() = 100; + + assert(TinySTL::Test::container_equal(v1, v2)); + } + void testCase9(){ + stdVec v1(5); + tsVec v2(5); + + auto p1 = v1.data(); + auto p2 = v2.data(); + *p1 = 10; ++p1; *p1 = 20; p1[2] = 100; + *p2 = 10; ++p2; *p2 = 20; p2[2] = 100; + + assert(TinySTL::Test::container_equal(v1, v2)); + } } } @@ -87,6 +129,10 @@ int main(){ //testCase3(); //testCase4(); //testCase5(); + //testCase6(); + //testCase7(); + //testCase8(); + //testCase9(); system("pause"); return 0; } \ No newline at end of file diff --git a/TinySTL/Test/VectorTest.h b/TinySTL/Test/VectorTest.h index a2f9aee..b91ffa7 100644 --- a/TinySTL/Test/VectorTest.h +++ b/TinySTL/Test/VectorTest.h @@ -25,6 +25,10 @@ namespace TinySTL{ void testCase3(); void testCase4(); void testCase5(); + void testCase6(); + void testCase7(); + void testCase8(); + void testCase9(); } }