ReactOS 0.4.15-dev-8119-g4fb2fdb
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)
8using namespace std;
9#endif
10
11//
12// TestCase class
13//
14class ForeachTest : public CPPUNIT_NS::TestCase
15{
20
21protected:
22 void foreach0();
23 void foreach1();
24};
25
27
28//
29// tests implementation
30//
31static 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}
52static 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}
_STLP_BEGIN_NAMESPACE _STLP_INLINE_LOOP _Function for_each(_InputIter __first, _InputIter __last, _Function __f)
Definition: _algo.h:59
pointer_to_unary_function< _Arg, _Result > ptr_fun(_Result(*__f)(_Arg))
void foreach1()
CPPUNIT_TEST_SUITE(ForeachTest)
CPPUNIT_TEST(foreach1)
void foreach0()
CPPUNIT_TEST(foreach0)
CPPUNIT_TEST_SUITE_END()
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
__kernel_size_t size_t
Definition: linux.h:237
static void sqr(int &a_)
static void increase(int &a_)
GLfloat GLfloat v1
Definition: glext.h:6062
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
Definition: features.h:417