From 4ca8cebd0a2a64bb91789e6c5cf7fcc64b34fc99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sat, 20 Dec 2014 11:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Test/AlgorithmTest.cpp | 25 +++++++++++++++++++++++++ TinySTL/Test/AlgorithmTest.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/TinySTL/Test/AlgorithmTest.cpp b/TinySTL/Test/AlgorithmTest.cpp index ffdf4b1..9650244 100644 --- a/TinySTL/Test/AlgorithmTest.cpp +++ b/TinySTL/Test/AlgorithmTest.cpp @@ -63,6 +63,27 @@ namespace TinySTL{ assert(TinySTL::Test::container_equal(v1, v2)); } + void testAllOf(){ + std::array 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 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 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 myvector{ 10, 20, 30 }; + std::vector 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; } \ No newline at end of file diff --git a/TinySTL/Test/AlgorithmTest.h b/TinySTL/Test/AlgorithmTest.h index 7540f48..1f17fc0 100644 --- a/TinySTL/Test/AlgorithmTest.h +++ b/TinySTL/Test/AlgorithmTest.h @@ -6,6 +6,7 @@ #include "../Algorithm.h" #include +#include #include #include @@ -16,6 +17,10 @@ namespace TinySTL{ void testMinMax(); void testHeapAlgorithm(); void testIsHeap(); + void testAllOf(); + void testNoneOf(); + void testAnyOf(); + void testForEach(); } }