From 194f194df2e9a224ed10e9175b7ed66895913f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Fri, 2 Jan 2015 10:02:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90queue=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/QueueTest.cpp | 69 ++++++++++++++++++++++++++++++++++++++ TinySTL/Test/QueueTest.h | 27 +++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 TinySTL/Test/QueueTest.cpp create mode 100644 TinySTL/Test/QueueTest.h diff --git a/TinySTL/Test/QueueTest.cpp b/TinySTL/Test/QueueTest.cpp new file mode 100644 index 0000000..b4d8222 --- /dev/null +++ b/TinySTL/Test/QueueTest.cpp @@ -0,0 +1,69 @@ +#include "QueueTest.h" + +namespace TinySTL{ + namespace QueueTest{ + void testCase1(){ + stdQ q1; + tsQ q2; + + for (auto i = 0; i != 10; ++i){ + q1.push(i); + q2.push(i); + } + for (auto i = 0; i != 10; ++i){ + assert(q1.front() == q2.front()); + q1.pop(); + q2.pop(); + } + } + void testCase2(){ + tsQ q1; + for (auto i = 0; i != 10; ++i) + q1.push(i); + auto q2(q1); + assert(q1 == q2); + assert(!(q1 != q2)); + } + void testCase3(){ + tsQ q; + assert(q.empty()); + assert(q.size() == 0); + + q.push(10); + q.push(11); + assert(!q.empty()); + assert(q.size() == 2); + } + void testCase4(){ + tsQ q; + q.push("front"); + q.push("back"); + + assert(q.front() == "front"); + assert(q.back() == "back"); + } + void testCase5(){ + tsQ q1, q2; + + q1.push(1); q1.push(2); q1.push(3); + q2.push(1); q2.push(2); + + assert(q1.size() == 3 && q2.size() == 2); + q1.swap(q2); + assert(q1.size() == 2 && q2.size() == 3); + TinySTL::swap(q1, q2); + assert(q1.size() == 3 && q2.size() == 2); + } + } +} + +//using namespace TinySTL::QueueTest; +//int main(){ +// testCase1(); +// testCase2(); +// testCase3(); +// testCase4(); +// testCase5(); +// system("pause"); +// return 0; +//} \ No newline at end of file diff --git a/TinySTL/Test/QueueTest.h b/TinySTL/Test/QueueTest.h new file mode 100644 index 0000000..80d3e5f --- /dev/null +++ b/TinySTL/Test/QueueTest.h @@ -0,0 +1,27 @@ +#ifndef _QUEUE_TEST_H_ +#define _QUEUE_TEST_H_ + +#include "TestUtil.h" + +#include "../Queue.h" +#include + +#include +#include + +namespace TinySTL{ + namespace QueueTest{ + template + using stdQ = std::queue < T > ; + template + using tsQ = TinySTL::queue < T > ; + + void testCase1(); + void testCase2(); + void testCase3(); + void testCase4(); + void testCase5(); + } +} + +#endif \ No newline at end of file