From 0a2c97bc4801fbd4b495dc9c6969b1468a8e86fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Tue, 23 Dec 2014 10:18:06 +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/StringTest.cpp | 56 ++++++++++++++++++++++++++++++++++--- TinySTL/Test/StringTest.h | 9 ++++++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/TinySTL/Test/StringTest.cpp b/TinySTL/Test/StringTest.cpp index d2c27a2..4ec35fc 100644 --- a/TinySTL/Test/StringTest.cpp +++ b/TinySTL/Test/StringTest.cpp @@ -72,15 +72,63 @@ namespace TinySTL{ std::cout << *it; std::cout << '\n'; } + void testCase5(){ + tsStr s; + assert(s.size() == 0); + assert(s.length() == 0); + + s = "hello, world"; + assert(s.size() == 12); + assert(s.size() == 12); + } + void testCase6(){ + stdStr s1("hello, world"); + tsStr s2("hello, world"); + + s1.resize(5); + s2.resize(5); + assert(TinySTL::Test::container_equal(s1, s2)); + + s1.resize(20, 'z'); + s2.resize(20, 'z'); + assert(TinySTL::Test::container_equal(s1, s2)); + + s1.resize(6, 'a'); + s2.resize(6, 'a'); + assert(TinySTL::Test::container_equal(s1, s2)); + + s1.resize(100); + s2.resize(100); + assert(TinySTL::Test::container_equal(s1, s2)); + } + void testCase7(){ + tsStr s; + s.reserve(10); + assert(s.capacity() == 10); + } + void testCase8(){ + tsStr s; + assert(s.empty()); + + s = "hello, world"; + assert(!s.empty()); + + s.clear(); + assert(s.empty()); + } } } using namespace TinySTL::StringTest; int main(){ - testCase1(); - testCase2(); - testCase3(); - testCase4(); + //testCase1(); + //testCase2(); + //testCase3(); + //testCase4(); + //testCase5(); + //testCase6(); + //testCase7(); + //testCase8(); system("pause"); return 0; } \ No newline at end of file diff --git a/TinySTL/Test/StringTest.h b/TinySTL/Test/StringTest.h index 5cf5e58..46bce42 100644 --- a/TinySTL/Test/StringTest.h +++ b/TinySTL/Test/StringTest.h @@ -13,6 +13,15 @@ namespace TinySTL{ namespace StringTest{ using stdStr = std::string; using tsStr = TinySTL::string; + + void testCase1(); + void testCase2(); + void testCase3(); + void testCase4(); + void testCase5(); + void testCase6(); + void testCase7(); + void testCase8(); } }