ReactOS  0.4.14-dev-52-g6116262
foreach_test.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <algorithm>
3 #include "fadapter.h"
4 
6 
7 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
8 using namespace std;
9 #endif
10 
11 //
12 // TestCase class
13 //
14 class ForeachTest : public CPPUNIT_NS::TestCase
15 {
17  CPPUNIT_TEST(foreach0);
18  CPPUNIT_TEST(foreach1);
20 
21 protected:
22  void foreach0();
23  void foreach1();
24 };
25 
27 
28 //
29 // tests implementation
30 //
31 static void increase(int& a_)
32 {
33  a_ += 1;
34 }
36 {
37  int numbers[10] = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 };
38 
39  for_each(numbers, numbers + 10, ptr_fun(increase));
40 
41  CPPUNIT_ASSERT(numbers[0]==2);
42  CPPUNIT_ASSERT(numbers[1]==2);
43  CPPUNIT_ASSERT(numbers[2]==3);
44  CPPUNIT_ASSERT(numbers[3]==4);
45  CPPUNIT_ASSERT(numbers[4]==6);
46  CPPUNIT_ASSERT(numbers[5]==9);
47  CPPUNIT_ASSERT(numbers[6]==14);
48  CPPUNIT_ASSERT(numbers[7]==22);
49  CPPUNIT_ASSERT(numbers[8]==35);
50  CPPUNIT_ASSERT(numbers[9]==56);
51 }
52 static void sqr(int& a_)
53 {
54  a_ = a_ * a_;
55 }
57 {
58  vector<int> v1(10);
59  for (int i = 0; (size_t)i < v1.size(); ++i)
60  v1[i] = i;
61  for_each(v1.begin(), v1.end(), ptr_fun(sqr) );
62 
63  CPPUNIT_ASSERT(v1[0]==0);
64  CPPUNIT_ASSERT(v1[1]==1);
65  CPPUNIT_ASSERT(v1[2]==4);
66  CPPUNIT_ASSERT(v1[3]==9);
67  CPPUNIT_ASSERT(v1[4]==16);
68  CPPUNIT_ASSERT(v1[5]==25);
69  CPPUNIT_ASSERT(v1[6]==36);
70  CPPUNIT_ASSERT(v1[7]==49);
71  CPPUNIT_ASSERT(v1[8]==64);
72  CPPUNIT_ASSERT(v1[9]==81);
73 }
#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
Definition: features.h:417
CPPUNIT_TEST_SUITE_REGISTRATION(ForeachTest)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
__kernel_size_t size_t
Definition: linux.h:237
void foreach0()
_STLP_BEGIN_NAMESPACE _STLP_INLINE_LOOP _Function for_each(_InputIter __first, _InputIter __last, _Function __f)
Definition: _algo.h:59
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
void foreach1()
static void increase(int &a_)
GLfloat GLfloat v1
Definition: glext.h:6062
static void sqr(int &a_)