添加测试用例

This commit is contained in:
邹晓航
2014-12-22 09:37:50 +08:00
parent 163f771a55
commit 0ff926ec23
2 changed files with 49 additions and 2 deletions

View File

@@ -37,13 +37,56 @@ namespace TinySTL{
auto v8 = std::move(v4);
assert(TinySTL::Test::container_equal(v7, v8));
}
void testCase3(){
tsVec<int> v1, v2;
for (int i = 0; i != 100; ++i){
v1.push_back(i);
v2.push_back(i);
}
assert(v1 == v2);
assert(!(v1 != v2));
}
void testCase4(){
tsVec<int> myvector;
for (int i = 1; i <= 5; i++) myvector.push_back(i);
std::cout << "myvector contains:";
for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
std::cout << "myvector contains:";
for (tsVec<int>::const_iterator it = myvector.cbegin(); it != myvector.cend(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
}
void testCase5(){
tsVec<int> myvector(5); // 5 default-constructed ints
int i = 0;
tsVec<int>::reverse_iterator rit = myvector.rbegin();
for (; rit != myvector.rend(); ++rit)
*rit = ++i;
std::cout << "myvector contains:";
for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
std::cout << "myvector contains(reverse order):";
for (tsVec<int>::reverse_iterator it = myvector.rbegin(); it != myvector.rend(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
}
}
}
using namespace TinySTL::VectorTest;
int main(){
testCase1();
testCase2();
//testCase1();
//testCase2();
//testCase3();
//testCase4();
//testCase5();
system("pause");
return 0;
}

View File

@@ -8,6 +8,7 @@
#include <array>
#include <cassert>
#include<iostream>
#include <iterator>
#include <string>
@@ -21,6 +22,9 @@ namespace TinySTL{
namespace VectorTest{
void testCase1();
void testCase2();
void testCase3();
void testCase4();
void testCase5();
}
}