From 4c0b9274225a1c462bd78b0c660db7cccdb3b015 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 11:22:59 +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 | 81 +++++++++++++++++++++++++++++++++---- TinySTL/Test/StringTest.h | 3 ++ 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/TinySTL/Test/StringTest.cpp b/TinySTL/Test/StringTest.cpp index 4ec35fc..6c5225a 100644 --- a/TinySTL/Test/StringTest.cpp +++ b/TinySTL/Test/StringTest.cpp @@ -116,19 +116,84 @@ namespace TinySTL{ s.clear(); assert(s.empty()); } + void testCase9(){ + tsStr s; + s.resize(10); + for (auto i = 0; i != s.size(); ++i) + s[i] = 'a' + i; + TinySTL::Test::print_container(s); + + s.back() = 'Z'; + s.front() = 'A'; + TinySTL::Test::print_container(s); + } + void testCase10(){ + stdStr s1; + tsStr s2; + for (auto i = 0; i != 10; ++i){ + s1.push_back('a' + i); + s2.push_back('a' + i); + } + assert(TinySTL::Test::container_equal(s1, s2)); + } + void testCase11(){ + stdStr s1; + tsStr s2; + + s1.insert(s1.begin(), 'A'); + s2.insert(s2.begin(), 'A'); + assert(TinySTL::Test::container_equal(s1, s2)); + + s1.insert(s1.end(), 2, 'Z'); + s2.insert(s2.end(), 2, 'Z'); + assert(TinySTL::Test::container_equal(s1, s2)); + + size_t n = 2; + s1.insert(2, 10, '@'); + s2.insert(2, 10, '@'); + assert(TinySTL::Test::container_equal(s1, s2)); + + s1.insert(0, "hello, world"); + s2.insert(0, "hello, world"); + assert(TinySTL::Test::container_equal(s1, s2)); + + s1.insert(s1.size() - 1, "zouxiaohang", 3); + s2.insert(s2.size() - 1, "zouxiaohang", 3); + assert(TinySTL::Test::container_equal(s1, s2)); + + stdStr s3; + tsStr s4; + + s3.insert(s3.begin(), s1.begin(), s1.end()); + s4.insert(s4.begin(), s2.begin(), s2.end()); + assert(TinySTL::Test::container_equal(s3, s4)); + + s3.insert(1, s1); + s4.insert(1, s2); + assert(TinySTL::Test::container_equal(s3, s4)); + + stdStr t1("zouxiaoHANG"); + tsStr t2("zouxiaoHANG"); + s3.insert(s3.size(), t1, 7, t1.size() - 7); + s4.insert(s4.size(), t2, 7, t2.size() - 7); + assert(TinySTL::Test::container_equal(s3, s4)); + } } } using namespace TinySTL::StringTest; int main(){ - //testCase1(); - //testCase2(); - //testCase3(); - //testCase4(); - //testCase5(); - //testCase6(); - //testCase7(); - //testCase8(); + testCase1(); + testCase2(); + testCase3(); + testCase4(); + testCase5(); + testCase6(); + testCase7(); + testCase8(); + testCase9(); + testCase10(); + testCase11(); system("pause"); return 0; } \ No newline at end of file diff --git a/TinySTL/Test/StringTest.h b/TinySTL/Test/StringTest.h index 46bce42..a0aeb8a 100644 --- a/TinySTL/Test/StringTest.h +++ b/TinySTL/Test/StringTest.h @@ -22,6 +22,9 @@ namespace TinySTL{ void testCase6(); void testCase7(); void testCase8(); + void testCase9(); + void testCase10(); + void testCase11(); } }