From 8d019b0063f8c389fb6769b7f720ed3e83e87dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Mon, 22 Dec 2014 09:27:43 +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/VectorTest.cpp | 49 +++++++++++++++++++++++++++++++++++++ TinySTL/Test/VectorTest.h | 27 ++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/TinySTL/Test/VectorTest.cpp b/TinySTL/Test/VectorTest.cpp index e69de29..2c69908 100644 --- a/TinySTL/Test/VectorTest.cpp +++ b/TinySTL/Test/VectorTest.cpp @@ -0,0 +1,49 @@ +#include "VectorTest.h" + +namespace TinySTL{ + namespace VectorTest{ + + void testCase1(){ + stdVec v1(10, "zxh"); + tsVec v2(10, "zxh"); + assert(TinySTL::Test::container_equal(v1, v2)); + + stdVec v3(10); + tsVec v4(10); + assert(TinySTL::Test::container_equal(v3, v4)); + + std::array arr = { "abc", "def", "ghi" }; + stdVec v5(std::begin(arr), std::end(arr)); + tsVec v6(std::begin(arr), std::end(arr)); + assert(TinySTL::Test::container_equal(v5, v6)); + } + void testCase2(){ + stdVec temp1(10, 0); + tsVec temp2(10, 0); + + auto v1(temp1); + auto v2(temp2); + assert(TinySTL::Test::container_equal(v1, v2)); + + auto v3(std::move(temp1)); + auto v4(std::move(temp2)); + assert(TinySTL::Test::container_equal(v3, v4)); + + auto v5 = v1; + auto v6 = v2; + assert(TinySTL::Test::container_equal(v5, v6)); + + auto v7 = std::move(v3); + auto v8 = std::move(v4); + assert(TinySTL::Test::container_equal(v7, v8)); + } + } +} + +using namespace TinySTL::VectorTest; +int main(){ + testCase1(); + testCase2(); + system("pause"); + return 0; +} \ No newline at end of file diff --git a/TinySTL/Test/VectorTest.h b/TinySTL/Test/VectorTest.h index e69de29..2fea093 100644 --- a/TinySTL/Test/VectorTest.h +++ b/TinySTL/Test/VectorTest.h @@ -0,0 +1,27 @@ +#ifndef _VECTOR_TEST_H_ +#define _VECTOR_TEST_H_ + +#include "../Vector.h" +#include "TestUtil.h" + +#include + +#include +#include +#include +#include + +template +using stdVec = std::vector < T > ; + +template +using tsVec = TinySTL::vector < T > ; + +namespace TinySTL{ + namespace VectorTest{ + void testCase1(); + void testCase2(); + } +} + +#endif \ No newline at end of file