添加测试用例
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef _STRING_TEST_H_
|
||||||
|
#define _STRING_TEST_H_
|
||||||
|
|
||||||
|
#include "TestUtil.h"
|
||||||
|
|
||||||
|
#include "../String.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
namespace TinySTL{
|
||||||
|
namespace StringTest{
|
||||||
|
using stdStr = std::string;
|
||||||
|
using tsStr = TinySTL::string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user