ReactOS 0.4.15-dev-8191-gbc6c731
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)
8using namespace std;
9#endif
10
11//
12// TestCase class
13//
14class Ptr2Test : public CPPUNIT_NS::TestCase
15{
22
23protected:
24 void ptrbin1();
25 void ptrbin2();
26 void ptrun1();
27 void ptrun2();
28};
29
31
32//
33// tests implementation
34//
35static int sum(int x_, int y_)
36{
37 return x_ + y_;
38}
39bool 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
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));
83 CPPUNIT_ASSERT(*p==2);
84}
_STLP_MOVE_TO_STD_NAMESPACE _InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred)
Definition: _algobase.c:214
pointer_to_unary_function< _Arg, _Result > ptr_fun(_Result(*__f)(_Arg))
void ptrbin1()
Definition: ptr2_test.cpp:43
CPPUNIT_TEST_SUITE(Ptr2Test)
void ptrbin2()
Definition: ptr2_test.cpp:56
void ptrun1()
Definition: ptr2_test.cpp:69
CPPUNIT_TEST(ptrun2)
CPPUNIT_TEST(ptrbin1)
void ptrun2()
Definition: ptr2_test.cpp:77
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST(ptrun1)
CPPUNIT_TEST(ptrbin2)
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLuint GLenum GLenum transform
Definition: glext.h:9407
GLfloat GLfloat p
Definition: glext.h:8902
Definition: features.h:417
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
#define even(p)
Definition: raisecond.c:50