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