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