From e61b59169722e72059d3a0f23c22a95ba161b8b0 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, 24 Dec 2014 12:16: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/StringTest.cpp | 38 ++++++++++++++++++++++++++++++------- TinySTL/Test/StringTest.h | 1 + 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/TinySTL/Test/StringTest.cpp b/TinySTL/Test/StringTest.cpp index a1e2db9..73b9acf 100644 --- a/TinySTL/Test/StringTest.cpp +++ b/TinySTL/Test/StringTest.cpp @@ -305,6 +305,29 @@ namespace TinySTL{ buffer[length] = '\0'; std::cout << "buffer contains: " << buffer << '\n'; } + void testCase19(){ + tsStr str("There are two needles in this haystack with needles."); + tsStr str2("needle"); + + auto found = str.find(str2); + assert(found == 14); + + found = str.find("needles are small", found + 1, 6); + assert(found == 44); + + found = str.find(tsStr("wuhan")); + assert(found == tsStr::npos); + + found = str.find("haystack"); + assert(found == 30); + + found = str.find('.'); + assert(found == 51); + + str.replace(str.find(str2), str2.length(), "preposition"); + assert(TinySTL::Test::container_equal(str, + tsStr("There are two prepositions in this haystack with needles."))); + } } } @@ -321,13 +344,14 @@ int main(){ //testCase9(); //testCase10(); //testCase11(); - testCase12(); - testCase13(); - testCase14(); - testCase15(); - testCase16(); - testCase17(); - testCase18(); + //testCase12(); + //testCase13(); + //testCase14(); + //testCase15(); + //testCase16(); + //testCase17(); + //testCase18(); + //testCase19(); system("pause"); return 0; } \ No newline at end of file diff --git a/TinySTL/Test/StringTest.h b/TinySTL/Test/StringTest.h index 57fb055..3b09e18 100644 --- a/TinySTL/Test/StringTest.h +++ b/TinySTL/Test/StringTest.h @@ -32,6 +32,7 @@ namespace TinySTL{ void testCase16(); void testCase17(); void testCase18(); + void testCase19(); } }