完成stack的测试
This commit is contained in:
59
TinySTL/Test/StackTest.cpp
Normal file
59
TinySTL/Test/StackTest.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "StackTest.h"
|
||||
|
||||
namespace TinySTL{
|
||||
namespace StackTest{
|
||||
void testCase1(){
|
||||
stdSt<int> st1;
|
||||
tsSt<int> 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<std::string> st;
|
||||
assert(st.empty());
|
||||
assert(st.size() == 0);
|
||||
|
||||
st.push("one");
|
||||
st.push("two");
|
||||
assert(!st.empty());
|
||||
assert(st.size() == 2);
|
||||
}
|
||||
void testCase3(){
|
||||
tsSt<int> st1;
|
||||
for (auto i = 0; i != 5; ++i)
|
||||
st1.push(i);
|
||||
auto st2(st1);
|
||||
assert(st1 == st2);
|
||||
assert(!(st1 != st2));
|
||||
}
|
||||
void testCase4(){
|
||||
tsSt<int> 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;
|
||||
//}
|
||||
26
TinySTL/Test/StackTest.h
Normal file
26
TinySTL/Test/StackTest.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _STACK_TEST_H_
|
||||
#define _STACK_TEST_H_
|
||||
|
||||
#include "TestUtil.h"
|
||||
|
||||
#include "../Stack.h"
|
||||
#include <stack>
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
namespace TinySTL{
|
||||
namespace StackTest{
|
||||
template<class T>
|
||||
using stdSt = std::stack < T > ;
|
||||
template<class T>
|
||||
using tsSt = TinySTL::stack < T > ;
|
||||
|
||||
void testCase1();
|
||||
void testCase2();
|
||||
void testCase3();
|
||||
void testCase4();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user