添加单元测试

This commit is contained in:
邹晓航
2014-12-20 11:51:19 +08:00
parent 8d09e98029
commit 4ca8cebd0a
2 changed files with 30 additions and 0 deletions

View File

@@ -63,6 +63,27 @@ namespace TinySTL{
assert(TinySTL::Test::container_equal(v1, v2));
}
void testAllOf(){
std::array<int, 8> foo = { 3, 5, 7, 11, 13, 17, 19, 23 };
assert(TinySTL::all_of(foo.begin(), foo.end(), [](int i){return i % 2; }));
}
void testNoneOf(){
std::array<int, 8> foo = { 1, 2, 4, 8, 16, 32, 64, 128 };
assert(TinySTL::none_of(foo.begin(), foo.end(), [](int i){return i < 0; }));
}
void testAnyOf(){
std::array<int, 7> foo = { 0, 1, -1, 3, -3, 5, -5 };
assert(std::any_of(foo.begin(), foo.end(), [](int i){return i < 0; }));
}
void testForEach(){
std::vector<int> myvector{ 10, 20, 30 };
std::vector<int> temp{ 11, 21, 31 };
TinySTL::for_each(myvector.begin(), myvector.end(), [&myvector](int& i){
++i;
});
assert(TinySTL::Test::container_equal(myvector, temp));
}
}
}
@@ -73,6 +94,10 @@ int main(){
//testMinMax();
//testHeapAlgorithm();
//testIsHeap();
//testAllOf();
//testNoneOf();
//testAnyOf();
//testForEach();
system("pause");
return 0;
}

View File

@@ -6,6 +6,7 @@
#include "../Algorithm.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <vector>
@@ -16,6 +17,10 @@ namespace TinySTL{
void testMinMax();
void testHeapAlgorithm();
void testIsHeap();
void testAllOf();
void testNoneOf();
void testAnyOf();
void testForEach();
}
}