ReactOS  0.4.14-dev-98-gb0d4763
ptr2_test.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <algorithm>
3 #include <functional>
4 
6 
7 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
8 using namespace std;
9 #endif
10 
11 //
12 // TestCase class
13 //
14 class Ptr2Test : public CPPUNIT_NS::TestCase
15 {
17  CPPUNIT_TEST(ptrbin1);
18  CPPUNIT_TEST(ptrbin2);
19  CPPUNIT_TEST(ptrun1);
20  CPPUNIT_TEST(ptrun2);
22 
23 protected:
24  void ptrbin1();
25  void ptrbin2();
26  void ptrun1();
27  void ptrun2();
28 };
29 
31 
32 //
33 // tests implementation
34 //
35 static int sum(int x_, int y_)
36 {
37  return x_ + y_;
38 }
39 bool even(int n_)
40 {
41  return(n_ % 2) == 0;
42 }
44 {
45  int input1 [4] = { 7, 2, 3, 5 };
46  int input2 [4] = { 1, 5, 5, 8 };
47 
48  int output [4];
49  transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, pointer_to_binary_function<int, int, int>(sum));
50 
51  CPPUNIT_ASSERT(output[0]==8);
52  CPPUNIT_ASSERT(output[1]==7);
53  CPPUNIT_ASSERT(output[2]==8);
54  CPPUNIT_ASSERT(output[3]==13);
55 }
57 {
58  int input1 [4] = { 7, 2, 3, 5 };
59  int input2 [4] = { 1, 5, 5, 8 };
60 
61  int output [4];
62  transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, ptr_fun(sum));
63 
64  CPPUNIT_ASSERT(output[0]==8);
65  CPPUNIT_ASSERT(output[1]==7);
66  CPPUNIT_ASSERT(output[2]==8);
67  CPPUNIT_ASSERT(output[3]==13);
68 }
70 {
71  int array [3] = { 1, 2, 3 };
72 
73  int* p = find_if((int*)array, (int*)array + 3, pointer_to_unary_function<int, bool>(even));
74  CPPUNIT_ASSERT(p != array+3);
75  CPPUNIT_ASSERT(*p==2);
76 }
78 {
79  int array [3] = { 1, 2, 3 };
80 
81  int* p = find_if((int*)array, (int*)array + 3, ptr_fun(even));
82  CPPUNIT_ASSERT(p != array+3);
83  CPPUNIT_ASSERT(*p==2);
84 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
pointer_to_unary_function< _Arg, _Result > ptr_fun(_Result(*__f)(_Arg))
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
void ptrbin1()
Definition: ptr2_test.cpp:43
Definition: features.h:417
_STLP_MOVE_TO_STD_NAMESPACE _InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred)
Definition: _algobase.c:214
void ptrun2()
Definition: ptr2_test.cpp:77
void ptrun1()
Definition: ptr2_test.cpp:69
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
bool even(int n_)
Definition: ptr2_test.cpp:39
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
CPPUNIT_TEST_SUITE_REGISTRATION(Ptr2Test)
GLuint GLenum GLenum transform
Definition: glext.h:9407
void ptrbin2()
Definition: ptr2_test.cpp:56
GLfloat GLfloat p
Definition: glext.h:8902