Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenptr2_test.cpp
Go to the documentation of this file.
00001 #include <vector> 00002 #include <algorithm> 00003 #include <functional> 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 Ptr2Test : public CPPUNIT_NS::TestCase 00015 { 00016 CPPUNIT_TEST_SUITE(Ptr2Test); 00017 CPPUNIT_TEST(ptrbin1); 00018 CPPUNIT_TEST(ptrbin2); 00019 CPPUNIT_TEST(ptrun1); 00020 CPPUNIT_TEST(ptrun2); 00021 CPPUNIT_TEST_SUITE_END(); 00022 00023 protected: 00024 void ptrbin1(); 00025 void ptrbin2(); 00026 void ptrun1(); 00027 void ptrun2(); 00028 }; 00029 00030 CPPUNIT_TEST_SUITE_REGISTRATION(Ptr2Test); 00031 00032 // 00033 // tests implementation 00034 // 00035 static int sum(int x_, int y_) 00036 { 00037 return x_ + y_; 00038 } 00039 bool even(int n_) 00040 { 00041 return(n_ % 2) == 0; 00042 } 00043 void Ptr2Test::ptrbin1() 00044 { 00045 int input1 [4] = { 7, 2, 3, 5 }; 00046 int input2 [4] = { 1, 5, 5, 8 }; 00047 00048 int output [4]; 00049 transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, pointer_to_binary_function<int, int, int>(sum)); 00050 00051 CPPUNIT_ASSERT(output[0]==8); 00052 CPPUNIT_ASSERT(output[1]==7); 00053 CPPUNIT_ASSERT(output[2]==8); 00054 CPPUNIT_ASSERT(output[3]==13); 00055 } 00056 void Ptr2Test::ptrbin2() 00057 { 00058 int input1 [4] = { 7, 2, 3, 5 }; 00059 int input2 [4] = { 1, 5, 5, 8 }; 00060 00061 int output [4]; 00062 transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, ptr_fun(sum)); 00063 00064 CPPUNIT_ASSERT(output[0]==8); 00065 CPPUNIT_ASSERT(output[1]==7); 00066 CPPUNIT_ASSERT(output[2]==8); 00067 CPPUNIT_ASSERT(output[3]==13); 00068 } 00069 void Ptr2Test::ptrun1() 00070 { 00071 int array [3] = { 1, 2, 3 }; 00072 00073 int* p = find_if((int*)array, (int*)array + 3, pointer_to_unary_function<int, bool>(even)); 00074 CPPUNIT_ASSERT(p != array+3); 00075 CPPUNIT_ASSERT(*p==2); 00076 } 00077 void Ptr2Test::ptrun2() 00078 { 00079 int array [3] = { 1, 2, 3 }; 00080 00081 int* p = find_if((int*)array, (int*)array + 3, ptr_fun(even)); 00082 CPPUNIT_ASSERT(p != array+3); 00083 CPPUNIT_ASSERT(*p==2); 00084 } Generated on Sun May 27 2012 04:35:40 for ReactOS by
1.7.6.1
|