ReactOS 0.4.15-dev-8245-gd24675b
iter_test.cpp
Go to the documentation of this file.
1#include <vector>
2#include <list>
3#include <algorithm>
4#include <numeric>
5
6#include "iota.h"
8
9#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
10using namespace std;
11#endif
12
13//
14// TestCase class
15//
16class IterTest : public CPPUNIT_NS::TestCase
17{
27
28protected:
29 void iter1();
30 void iter3();
31 void iter4();
32 void iterswp0();
33 void iterswp1();
34 void iterswp2();
35 void iterswp3();
36};
37
39
40//
41// tests implementation
42//
44{
45 vector<const char*> v; // Vector of character strings.
46 v.push_back("zippy"); // First element.
47 v.push_back("motorboy"); // Second element.
48 typedef vector<const char*> vec;
49 unsigned counter = 0;
50 for (vec::iterator i = v.begin(); i != v.end(); ++i, ++counter) {
51 switch (counter) {
52 case 0:
53 CPPUNIT_ASSERT(!strcmp(*i, "zippy"));
54 break;
55 case 1:
56 CPPUNIT_ASSERT(!strcmp(*i, "motorboy"));
57 break;
58 default:
60 }
61 }
62}
64{
65 typedef vector<const char*> Vec;
66 Vec v; // Vector of character strings.
67 v.push_back("zippy"); // First element.
68 v.push_back("motorboy"); // Second element.
69 Vec::reverse_iterator it;
70 unsigned counter = 0;
71 for (it = v.rbegin(); it != v.rend(); ++it, ++counter) {
72 switch (counter) {
73 case 1:
74 CPPUNIT_ASSERT(!strcmp(*it, "zippy"));
75 break;
76 case 0:
77 CPPUNIT_ASSERT(!strcmp(*it, "motorboy"));
78 break;
79 default:
81 }
82 }
83}
85{
86 vector<int> v; // Empty vector of integers.
87 v.push_back(1);
88 v.push_back(2);
89 v.push_back(3);
90 // Position immediately after last item.
92 // Move back one and then access.
93 CPPUNIT_ASSERT((*--i)==3);
94 i -= 2; // Jump back two items.
95 CPPUNIT_ASSERT((*i)==1);
96}
98{
99 int numbers[6] = { 0, 1, 2, 3, 4, 5 };
100
101 iter_swap(numbers, numbers + 3);
102
103 CPPUNIT_ASSERT(numbers[0]==3);
104 CPPUNIT_ASSERT(numbers[1]==1);
105 CPPUNIT_ASSERT(numbers[2]==2);
106 CPPUNIT_ASSERT(numbers[3]==0);
107 CPPUNIT_ASSERT(numbers[4]==4);
108 CPPUNIT_ASSERT(numbers[5]==5);
109
110}
112{
113 vector<int> v1(6);
114 __iota(v1.begin(), v1.end(), 0);
115 iter_swap( v1.begin(), v1.begin() + 3 );
116
117 CPPUNIT_ASSERT(v1[0]==3);
118 CPPUNIT_ASSERT(v1[1]==1);
119 CPPUNIT_ASSERT(v1[2]==2);
120 CPPUNIT_ASSERT(v1[3]==0);
121 CPPUNIT_ASSERT(v1[4]==4);
122 CPPUNIT_ASSERT(v1[5]==5);
123}
125{
126 vector<bool> boolVector;
127
128 boolVector.push_back( true );
129 boolVector.push_back( false );
130
131 vector<bool>::iterator i1 = boolVector.begin();
132 vector<bool>::iterator i2 = boolVector.begin();
133 ++i2;
134
135 bool v0 = *i1;
136 bool v1 = *i2;
137
138 iter_swap( i1, i2 );
139
140 CPPUNIT_ASSERT(( *i1 == v1 && *i2 == v0 ));
141}
142
143
145{
146 vector<int> vvref(10, 10);
147 vector<int> lvref(10, 20);
148
149 vector<vector<int> > vvints(4, vvref);
150 list<vector<int> > lvints(4, lvref);
151
152 iter_swap(vvints.begin(), lvints.begin());
153 CPPUNIT_CHECK( vvints.front() == lvref );
154 CPPUNIT_CHECK( lvints.front() == vvref );
155
156 //const vector<vector<int> > &cvvints = vvints;
157 //iter_swap(cvvints.begin(), lvints.begin());
158 //iter_swap(lvints.begin(), cvvints.begin());
159
160#if defined (STLPORT) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
161 int *pvvint = &vvints.front().front();
162 int *plvint = &lvints.front().front();
163
164 iter_swap(vvints.begin(), lvints.begin());
165 //Check that elements have been swaped:
166 CPPUNIT_CHECK( pvvint == &lvints.front().front() );
167 CPPUNIT_CHECK( plvint == &vvints.front().front() );
168#endif
169}
_STLP_MOVE_TO_STD_NAMESPACE void iter_swap(_ForwardIter1 __i1, _ForwardIter2 __i2)
Definition: _algobase.h:120
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
void iter3()
Definition: iter_test.cpp:63
CPPUNIT_TEST(iter3)
CPPUNIT_TEST(iter4)
CPPUNIT_TEST_SUITE_END()
void iterswp0()
Definition: iter_test.cpp:97
void iterswp3()
Definition: iter_test.cpp:144
void iterswp2()
Definition: iter_test.cpp:124
CPPUNIT_TEST(iterswp2)
void iter4()
Definition: iter_test.cpp:84
CPPUNIT_TEST(iter1)
CPPUNIT_TEST(iterswp3)
void iter1()
Definition: iter_test.cpp:43
void iterswp1()
Definition: iter_test.cpp:111
CPPUNIT_TEST(iterswp0)
CPPUNIT_TEST(iterswp1)
CPPUNIT_TEST_SUITE(IterTest)
#define CPPUNIT_CHECK(X)
Definition: cppunit_mini.h:195
#define CPPUNIT_FAIL
Definition: cppunit_mini.h:206
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
FT_Vector * vec
Definition: ftbbox.c:448
const GLdouble * v
Definition: gl.h:2040
GLfloat v0
Definition: glext.h:6061
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
void __iota(_It __first, _It __last, _Tp __val)
Definition: iota.h:8
Definition: features.h:417
value_type * iterator
Definition: _vector.h:124