From 37ee21aebacab82da8c23182e352084c68dc2fbe 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 09:55:13 +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 | 55 +++++++++++++++++++++++++++++++++++++ TinySTL/Test/StringTest.h | 19 +++++++++++++ 2 files changed, 74 insertions(+) diff --git a/TinySTL/Test/StringTest.cpp b/TinySTL/Test/StringTest.cpp index e69de29..110fbe9 100644 --- a/TinySTL/Test/StringTest.cpp +++ b/TinySTL/Test/StringTest.cpp @@ -0,0 +1,55 @@ +#include "StringTest.h" + +namespace TinySTL{ + namespace StringTest{ + + void testCase1(){ + const char *ptr = "hello world"; + + stdStr s1(ptr); + tsStr s2(ptr); + assert(TinySTL::Test::container_equal(s1, s2)); + + stdStr s3(ptr, 5); + tsStr s4(ptr, 5); + assert(TinySTL::Test::container_equal(s3, s4)); + + stdStr s5(10, 'z'); + tsStr s6(10, 'z'); + assert(TinySTL::Test::container_equal(s5, s6)); + + char arr[] = "zouxiaohang love cpp"; + stdStr s7(std::begin(arr), std::end(arr)); + tsStr s8(std::begin(arr), std::end(arr)); + assert(TinySTL::Test::container_equal(s7, s8)); + } + void testCase2(){ + stdStr temp1("hello, world"); + tsStr temp2("hello, world"); + + stdStr s1(temp1); + tsStr s2(temp2); + assert(TinySTL::Test::container_equal(s1, s2)); + + stdStr s3(std::move(s1)); + tsStr s4(std::move(s2)); + assert(TinySTL::Test::container_equal(s3, s4)); + + stdStr s5(temp1, 1); + tsStr s6(temp2, 1); + assert(TinySTL::Test::container_equal(s5, s6)); + + stdStr s7(temp1, 0, 5); + tsStr s8(temp2, 0, 5); + assert(TinySTL::Test::container_equal(s7, s8)); + } + } +} + +using namespace TinySTL::StringTest; +int main(){ + testCase1(); + testCase2(); + system("pause"); + return 0; +} \ No newline at end of file diff --git a/TinySTL/Test/StringTest.h b/TinySTL/Test/StringTest.h index e69de29..5cf5e58 100644 --- a/TinySTL/Test/StringTest.h +++ b/TinySTL/Test/StringTest.h @@ -0,0 +1,19 @@ +#ifndef _STRING_TEST_H_ +#define _STRING_TEST_H_ + +#include "TestUtil.h" + +#include "../String.h" +#include + +#include +#include + +namespace TinySTL{ + namespace StringTest{ + using stdStr = std::string; + using tsStr = TinySTL::string; + } +} + +#endif \ No newline at end of file