From 4e48d0061e786b047e8b9b2fd282377da88df1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sat, 3 Jan 2015 12:03:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90stack=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Test/StackTest.cpp | 59 ++++++++++++++++++++++++++++++++++++++ TinySTL/Test/StackTest.h | 26 +++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 TinySTL/Test/StackTest.cpp create mode 100644 TinySTL/Test/StackTest.h diff --git a/TinySTL/Test/StackTest.cpp b/TinySTL/Test/StackTest.cpp new file mode 100644 index 0000000..36a2cef --- /dev/null +++ b/TinySTL/Test/StackTest.cpp @@ -0,0 +1,59 @@ +#include "StackTest.h" + +namespace TinySTL{ + namespace StackTest{ + void testCase1(){ + stdSt st1; + tsSt st2; + + for (auto i = 0; i != 10; ++i){ + st1.push(i); + st2.push(i); + } + for (auto i = 0; i != 10; ++i){ + assert(st1.top() == st2.top()); + st1.pop(); + st2.pop(); + } + } + void testCase2(){ + tsSt st; + assert(st.empty()); + assert(st.size() == 0); + + st.push("one"); + st.push("two"); + assert(!st.empty()); + assert(st.size() == 2); + } + void testCase3(){ + tsSt st1; + for (auto i = 0; i != 5; ++i) + st1.push(i); + auto st2(st1); + assert(st1 == st2); + assert(!(st1 != st2)); + } + void testCase4(){ + tsSt st1, st2; + st1.push(1); st1.push(2); st1.push(3); + st2.push(1); st2.push(2); + assert(st1.size() == 3 && st2.size() == 2); + st1.swap(st2); + assert(st1.size() == 2 && st2.size() == 3); + TinySTL::swap(st1, st2); + assert(st1.size() == 3 && st2.size() == 2); + } + } +} + +//using namespace TinySTL::StackTest; +//int main(){ +// testCase1(); +// testCase2(); +// testCase3(); +// testCase4(); +// +// system("pause"); +// return 0; +//} \ No newline at end of file diff --git a/TinySTL/Test/StackTest.h b/TinySTL/Test/StackTest.h new file mode 100644 index 0000000..ad45679 --- /dev/null +++ b/TinySTL/Test/StackTest.h @@ -0,0 +1,26 @@ +#ifndef _STACK_TEST_H_ +#define _STACK_TEST_H_ + +#include "TestUtil.h" + +#include "../Stack.h" +#include + +#include +#include + +namespace TinySTL{ + namespace StackTest{ + template + using stdSt = std::stack < T > ; + template + using tsSt = TinySTL::stack < T > ; + + void testCase1(); + void testCase2(); + void testCase3(); + void testCase4(); + } +} + +#endif \ No newline at end of file