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