ReactOS  0.4.14-dev-98-gb0d4763
rm_cp_test.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <algorithm>
3 
5 
6 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
7 using namespace std;
8 #endif
9 
10 //
11 // TestCase class
12 //
13 class RmCpTest : public CPPUNIT_NS::TestCase
14 {
16  CPPUNIT_TEST(remcopy1);
17  CPPUNIT_TEST(remcpif1);
18  CPPUNIT_TEST(remif1);
19  CPPUNIT_TEST(remove1);
20  CPPUNIT_TEST(repcpif1);
21  CPPUNIT_TEST(replace0);
22  CPPUNIT_TEST(replace1);
23  CPPUNIT_TEST(replcpy1);
24  CPPUNIT_TEST(replif1);
25  CPPUNIT_TEST(revcopy1);
26  CPPUNIT_TEST(reverse1);
28 
29 protected:
30  void remcopy1();
31  void remcpif1();
32  void remif1();
33  void remove1();
34  void repcpif1();
35  void replace0();
36  void replace1();
37  void replcpy1();
38  void replif1();
39  void revcopy1();
40  void reverse1();
41 
42 };
43 
45 
46 static bool odd(int a_)
47 {
48  return (a_ % 2) != 0;
49 }
50 //
51 // tests implementation
52 //
53 
55 {
56  int numbers[6] = { 0, 1, 2, 3, 4, 5 };
57 
58  reverse(numbers, numbers + 6);
59  CPPUNIT_ASSERT(numbers[0]==5);
60  CPPUNIT_ASSERT(numbers[1]==4);
61  CPPUNIT_ASSERT(numbers[2]==3);
62  CPPUNIT_ASSERT(numbers[3]==2);
63  CPPUNIT_ASSERT(numbers[4]==1);
64  CPPUNIT_ASSERT(numbers[5]==0);
65 }
66 
68 {
69  int numbers[6] = { 0, 1, 2, 3, 4, 5 };
70 
71  int result[6];
72  reverse_copy((int*)numbers, (int*)numbers + 6, (int*)result);
73  // 5 4 3 2 1 0
74  CPPUNIT_ASSERT(result[0]==5);
75  CPPUNIT_ASSERT(result[1]==4);
76  CPPUNIT_ASSERT(result[2]==3);
77  CPPUNIT_ASSERT(result[3]==2);
78  CPPUNIT_ASSERT(result[4]==1);
79  CPPUNIT_ASSERT(result[5]==0);
80 }
81 
83 {
84  vector <int> v1(10);
85  for (int i = 0; (size_t)i < v1.size(); ++i)
86  v1[i] = i % 5;
87 
88  replace_if(v1.begin(), v1.end(), odd, 42);
89 
90  // 0 42 2 42 4 0 42 2 42 4
91  CPPUNIT_ASSERT(v1[0]==0);
92  CPPUNIT_ASSERT(v1[1]==42);
93  CPPUNIT_ASSERT(v1[2]==2);
94  CPPUNIT_ASSERT(v1[3]==42);
95  CPPUNIT_ASSERT(v1[4]==4);
96  CPPUNIT_ASSERT(v1[5]==0);
97  CPPUNIT_ASSERT(v1[6]==42);
98  CPPUNIT_ASSERT(v1[7]==2);
99  CPPUNIT_ASSERT(v1[8]==42);
100  CPPUNIT_ASSERT(v1[9]==4);
101 }
102 
104 {
105  int numbers[6] = { 0, 1, 2, 0, 1, 2 };
106  int result[6] = { 0, 0, 0, 0, 0, 0 };
107 
108  replace_copy((int*)numbers, (int*)numbers + 6, (int*)result, 2, 42);
109  CPPUNIT_ASSERT(result[0]==0);
110  CPPUNIT_ASSERT(result[1]==1);
111  CPPUNIT_ASSERT(result[2]==42);
112  CPPUNIT_ASSERT(result[3]==0);
113  CPPUNIT_ASSERT(result[4]==1);
114  CPPUNIT_ASSERT(result[5]==42);
115 }
116 
118 {
119  int numbers[6] = { 0, 1, 2, 0, 1, 2 };
120 
121  replace(numbers, numbers + 6, 2, 42);
122 
123  // 0 1 42 0 1 42
124  CPPUNIT_ASSERT(numbers[0]==0);
125  CPPUNIT_ASSERT(numbers[1]==1);
126  CPPUNIT_ASSERT(numbers[2]==42);
127  CPPUNIT_ASSERT(numbers[3]==0);
128  CPPUNIT_ASSERT(numbers[4]==1);
129  CPPUNIT_ASSERT(numbers[5]==42);
130 }
131 
133 {
134  vector <int> v1(10);
135  for (int i = 0; (size_t)i < v1.size(); ++i)
136  v1[i] = i % 5;
137  replace(v1.begin(), v1.end(), 2, 42);
138 
139  // 0 1 2 3 4 0 1 2 3 4
140  // 0 1 42 3 4 0 1 42 3 4
141  CPPUNIT_ASSERT(v1[0]==0);
142  CPPUNIT_ASSERT(v1[1]==1);
143  CPPUNIT_ASSERT(v1[2]==42);
144  CPPUNIT_ASSERT(v1[3]==3);
145  CPPUNIT_ASSERT(v1[4]==4);
146  CPPUNIT_ASSERT(v1[5]==0);
147  CPPUNIT_ASSERT(v1[6]==1);
148  CPPUNIT_ASSERT(v1[7]==42);
149  CPPUNIT_ASSERT(v1[8]==3);
150  CPPUNIT_ASSERT(v1[9]==4);
151 }
152 
154 {
155  vector <int> v1(10);
156  for (int i = 0; (size_t)i < v1.size(); ++i)
157  v1[i] = i % 5;
158  vector <int> v2(v1.size());
159 
160  // 0 1 2 3 4 0 1 2 3 4
161  // 0 1 2 3 4 0 1 2 3 4
162  // 0 42 2 42 4 0 42 2 42 4
163  replace_copy_if(v1.begin(), v1.end(), v2.begin(), odd, 42);
164  CPPUNIT_ASSERT(v1[0]==0);
165  CPPUNIT_ASSERT(v1[1]==1);
166  CPPUNIT_ASSERT(v1[2]==2);
167  CPPUNIT_ASSERT(v1[3]==3);
168  CPPUNIT_ASSERT(v1[4]==4);
169  CPPUNIT_ASSERT(v1[5]==0);
170  CPPUNIT_ASSERT(v1[6]==1);
171  CPPUNIT_ASSERT(v1[7]==2);
172  CPPUNIT_ASSERT(v1[8]==3);
173  CPPUNIT_ASSERT(v1[9]==4);
174 
175  CPPUNIT_ASSERT(v2[0]==0);
176  CPPUNIT_ASSERT(v2[1]==42);
177  CPPUNIT_ASSERT(v2[2]==2);
178  CPPUNIT_ASSERT(v2[3]==42);
179  CPPUNIT_ASSERT(v2[4]==4);
180  CPPUNIT_ASSERT(v2[5]==0);
181  CPPUNIT_ASSERT(v2[6]==42);
182  CPPUNIT_ASSERT(v2[7]==2);
183  CPPUNIT_ASSERT(v2[8]==42);
184  CPPUNIT_ASSERT(v2[9]==4);
185 }
186 
188 {
189  int numbers[6] = { 1, 2, 3, 1, 2, 3 };
190  remove((int*)numbers, (int*)numbers + 6, 1);
191 
192  // 2 3 2 3 2 3
193  CPPUNIT_ASSERT(numbers[0]==2);
194  CPPUNIT_ASSERT(numbers[1]==3);
195  CPPUNIT_ASSERT(numbers[2]==2);
196  CPPUNIT_ASSERT(numbers[3]==3);
197  CPPUNIT_ASSERT(numbers[4]==2);
198  CPPUNIT_ASSERT(numbers[5]==3);
199 }
200 
202 {
203  int numbers[6] = { 0, 0, 1, 1, 2, 2 };
204 
205  remove_if((int*)numbers, (int*)numbers + 6, odd);
206 
207  // 0 0 2 2 2 2
208  CPPUNIT_ASSERT(numbers[0]==0);
209  CPPUNIT_ASSERT(numbers[1]==0);
210  CPPUNIT_ASSERT(numbers[2]==2);
211  CPPUNIT_ASSERT(numbers[3]==2);
212  CPPUNIT_ASSERT(numbers[4]==2);
213  CPPUNIT_ASSERT(numbers[5]==2);
214 }
215 
217 {
218  int numbers[6] = { 1, 2, 3, 1, 2, 3 };
219  int result[6] = { 0, 0, 0, 0, 0, 0 };
220 
221  remove_copy((int*)numbers, (int*)numbers + 6, (int*)result, 2);
222 
223  CPPUNIT_ASSERT(result[0]==1);
224  CPPUNIT_ASSERT(result[1]==3);
225  CPPUNIT_ASSERT(result[2]==1);
226  CPPUNIT_ASSERT(result[3]==3);
227  CPPUNIT_ASSERT(result[4]==0);
228  CPPUNIT_ASSERT(result[5]==0);
229 }
230 
232 {
233  int numbers[6] = { 1, 2, 3, 1, 2, 3 };
234  int result[6] = { 0, 0, 0, 0, 0, 0 };
235 
236  remove_copy_if((int*)numbers, (int*)numbers + 6, (int*)result, odd);
237 
238  // 2 2 0 0 0 0
239  CPPUNIT_ASSERT(result[0]==2);
240  CPPUNIT_ASSERT(result[1]==2);
241  CPPUNIT_ASSERT(result[2]==0);
242  CPPUNIT_ASSERT(result[3]==0);
243  CPPUNIT_ASSERT(result[4]==0);
244  CPPUNIT_ASSERT(result[5]==0);
245 }
void reverse1()
Definition: rm_cp_test.cpp:54
_STLP_INLINE_LOOP _OutputIter replace_copy_if(_Iterator __first, _Iterator __last, _OutputIter __result, _Predicate __pred, const _Tp &__new_value)
Definition: _algo.h:209
_STLP_INLINE_LOOP _OutputIter replace_copy(_InputIter __first, _InputIter __last, _OutputIter __result, const _Tp &__old_value, const _Tp &__new_value)
Definition: _algo.h:199
void replace1()
Definition: rm_cp_test.cpp:132
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
Definition: unary.h:11
static bool odd(int a_)
Definition: rm_cp_test.cpp:46
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
void replcpy1()
Definition: rm_cp_test.cpp:103
_STLP_MOVE_TO_STD_NAMESPACE void reverse(_BidirectionalIter __first, _BidirectionalIter __last)
Definition: _algo.h:332
void replif1()
Definition: rm_cp_test.cpp:82
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
INT replace(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *doMore)
Definition: replace.c:47
_STLP_INLINE_LOOP void replace_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred, const _Tp &__new_value)
Definition: _algo.h:190
__kernel_size_t size_t
Definition: linux.h:237
void remcpif1()
Definition: rm_cp_test.cpp:231
void remif1()
Definition: rm_cp_test.cpp:201
_STLP_INLINE_LOOP _OutputIter remove_copy(_InputIter __first, _InputIter __last, _OutputIter __result, const _Tp &__val)
Definition: _algo.h:239
_STLP_INLINE_LOOP _ForwardIter remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred)
Definition: _algo.h:278
CPPUNIT_TEST_SUITE_REGISTRATION(RmCpTest)
void replace0()
Definition: rm_cp_test.cpp:117
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
void repcpif1()
Definition: rm_cp_test.cpp:153
void remcopy1()
Definition: rm_cp_test.cpp:216
void revcopy1()
Definition: rm_cp_test.cpp:67
_STLP_INLINE_LOOP _OutputIter reverse_copy(_BidirectionalIter __first, _BidirectionalIter __last, _OutputIter __result)
Definition: _algo.h:339
int remove
Definition: msacm.c:1353
void remove1()
Definition: rm_cp_test.cpp:187
_STLP_INLINE_LOOP _OutputIter remove_copy_if(_InputIter __first, _InputIter __last, _OutputIter __result, _Predicate __pred)
Definition: _algo.h:252
GLuint64EXT * result
Definition: glext.h:11304
GLfloat GLfloat v1
Definition: glext.h:6062