Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenforeach_test.cpp
Go to the documentation of this file.
00001 #include <vector> 00002 #include <algorithm> 00003 #include "fadapter.h" 00004 00005 #include "cppunit/cppunit_proxy.h" 00006 00007 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 00008 using namespace std; 00009 #endif 00010 00011 // 00012 // TestCase class 00013 // 00014 class ForeachTest : public CPPUNIT_NS::TestCase 00015 { 00016 CPPUNIT_TEST_SUITE(ForeachTest); 00017 CPPUNIT_TEST(foreach0); 00018 CPPUNIT_TEST(foreach1); 00019 CPPUNIT_TEST_SUITE_END(); 00020 00021 protected: 00022 void foreach0(); 00023 void foreach1(); 00024 }; 00025 00026 CPPUNIT_TEST_SUITE_REGISTRATION(ForeachTest); 00027 00028 // 00029 // tests implementation 00030 // 00031 static void increase(int& a_) 00032 { 00033 a_ += 1; 00034 } 00035 void ForeachTest::foreach0() 00036 { 00037 int numbers[10] = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 }; 00038 00039 for_each(numbers, numbers + 10, ptr_fun(increase)); 00040 00041 CPPUNIT_ASSERT(numbers[0]==2); 00042 CPPUNIT_ASSERT(numbers[1]==2); 00043 CPPUNIT_ASSERT(numbers[2]==3); 00044 CPPUNIT_ASSERT(numbers[3]==4); 00045 CPPUNIT_ASSERT(numbers[4]==6); 00046 CPPUNIT_ASSERT(numbers[5]==9); 00047 CPPUNIT_ASSERT(numbers[6]==14); 00048 CPPUNIT_ASSERT(numbers[7]==22); 00049 CPPUNIT_ASSERT(numbers[8]==35); 00050 CPPUNIT_ASSERT(numbers[9]==56); 00051 } 00052 static void sqr(int& a_) 00053 { 00054 a_ = a_ * a_; 00055 } 00056 void ForeachTest::foreach1() 00057 { 00058 vector<int> v1(10); 00059 for (int i = 0; (size_t)i < v1.size(); ++i) 00060 v1[i] = i; 00061 for_each(v1.begin(), v1.end(), ptr_fun(sqr) ); 00062 00063 CPPUNIT_ASSERT(v1[0]==0); 00064 CPPUNIT_ASSERT(v1[1]==1); 00065 CPPUNIT_ASSERT(v1[2]==4); 00066 CPPUNIT_ASSERT(v1[3]==9); 00067 CPPUNIT_ASSERT(v1[4]==16); 00068 CPPUNIT_ASSERT(v1[5]==25); 00069 CPPUNIT_ASSERT(v1[6]==36); 00070 CPPUNIT_ASSERT(v1[7]==49); 00071 CPPUNIT_ASSERT(v1[8]==64); 00072 CPPUNIT_ASSERT(v1[9]==81); 00073 } Generated on Sat May 26 2012 04:34:15 for ReactOS by
1.7.6.1
|