ReactOS 0.4.16-dev-306-g647d351
equal_test.cpp
Go to the documentation of this file.
1#include <vector>
2#include <algorithm>
3#include <functional>
5
6#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
7using namespace std;
8#endif
9
10//
11// TestCase class
12//
13class EqualTest : public CPPUNIT_NS::TestCase
14{
24
25protected:
26 void equal_range0();
27 void equal_range1();
28 void equal_range2();
29 void equal0();
30 void equal1();
31 void equal2();
32 void equalto();
33 static bool values_squared(int a_, int b_);
34};
35
37
38//
39// tests implementation
40//
42{
43 int numbers[10] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3 };
44 pair<int*, int*> range = equal_range((int*)numbers, (int*)numbers + 10, 2);
45 CPPUNIT_ASSERT( (range.first - numbers) == 4 );
46 CPPUNIT_ASSERT( (range.second - numbers) == 8 );
47}
48
50{
51 typedef vector <int> IntVec;
52 IntVec v(10);
53 for (int i = 0; (size_t)i < v.size(); ++i)
54 v[i] = i / 3;
55
57 CPPUNIT_ASSERT( (range.first - v.begin()) == 6 );
58 CPPUNIT_ASSERT( (range.second - v.begin()) == 9 );
59 for (; range.first != range.second; ++range.first)
60 CPPUNIT_ASSERT( *range.first == 2 );
61
62 range = equal_range(v.begin(), v.end(), 4);
63 CPPUNIT_ASSERT( range.first == range.second );
64 CPPUNIT_ASSERT( range.first == v.end() );
65}
66
67struct Test {
68#if defined (__DMC__)
69 Test();
70#endif
71
72 Test(int val) : value(val) {}
73 int value;
74
75 bool operator == (int i) const
76 { return value == i; }
77};
78
79bool operator < (const Test& v1, int v2)
80{ return v1.value < v2; }
81
82bool operator < (int v1, const Test& v2)
83{ return v1 < v2.value; }
84
85#if defined (_MSC_VER) && !defined (STLPORT)
86bool operator < (const Test& v1, const Test& v2)
87{ return v1.value < v2.value; }
88#endif
89
91{
92 char chars[] = "aabbccddggghhklllmqqqqssyyzz";
93
94 const unsigned count = sizeof(chars) - 1;
95 pair<char*, char*> range = equal_range((char*)chars, (char*)chars + count, 'q', less<char>());
96 CPPUNIT_ASSERT( (range.first - chars) == 18 );
97 CPPUNIT_ASSERT( (range.second - chars) == 22 );
98 for (; range.first != range.second; ++range.first)
99 CPPUNIT_ASSERT( *range.first == 'q' );
100
101 range = equal_range((char*)chars, (char*)chars + count, 'm', less<char>());
102 CPPUNIT_ASSERT( (range.second - range.first) == 1 );
103 CPPUNIT_ASSERT( *range.first == 'm' );
104
105 vector<Test> tv;
108
109 for (int i = 0; i < 10; ++i) {
110 tv.push_back(i);
111 }
112
113 it = upper_bound(tv.begin(), tv.end(), 5);
114 CPPUNIT_ASSERT( it != tv.end() );
115 CPPUNIT_ASSERT( *it == 6 );
116
117 it = lower_bound(tv.begin(), tv.end(), 5);
118 CPPUNIT_ASSERT( it != tv.end() );
119 CPPUNIT_ASSERT( *it == 5 );
120
121 p = equal_range(tv.begin(), tv.end(), 5);
122 CPPUNIT_ASSERT( p.first != p.second );
123 CPPUNIT_ASSERT( p.first != tv.end() );
124 CPPUNIT_ASSERT( p.second != tv.end() );
125 CPPUNIT_ASSERT( *p.first == 5 );
126 CPPUNIT_ASSERT( *p.second == 6 );
127}
128
130{
131 int numbers1[5] = { 1, 2, 3, 4, 5 };
132 int numbers2[5] = { 1, 2, 4, 8, 16 };
133 int numbers3[2] = { 1, 2 };
134
135 CPPUNIT_ASSERT( !equal(numbers1, numbers1 + 5, numbers2) );
136 CPPUNIT_ASSERT( equal(numbers3, numbers3 + 2, numbers1) );
137}
138
140{
141 vector <int> v1(10);
142 for (int i = 0; (size_t)i < v1.size(); ++i)
143 v1[i] = i;
144 vector <int> v2(10);
145 CPPUNIT_ASSERT( !equal(v1.begin(), v1.end(), v2.begin()) );
146
147 copy(v1.begin(), v1.end(), v2.begin());
148 CPPUNIT_ASSERT( equal(v1.begin(), v1.end(), v2.begin()) )
149}
150
152{
153 vector <int> v1(10);
154 vector <int> v2(10);
155 for (int i = 0; (size_t)i < v1.size(); ++i) {
156 v1[i] = i;
157 v2[i] = i * i;
158 }
159 CPPUNIT_ASSERT( equal(v1.begin(), v1.end(), v2.begin(), values_squared) );
160}
161
163{
164 int input1 [4] = { 1, 7, 2, 2 };
165 int input2 [4] = { 1, 6, 2, 3 };
166
167 int output [4];
168 transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, equal_to<int>());
169 CPPUNIT_ASSERT( output[0] == 1 );
170 CPPUNIT_ASSERT( output[1] == 0 );
171 CPPUNIT_ASSERT( output[2] == 1 );
172 CPPUNIT_ASSERT( output[3] == 0 );
173}
174
175bool EqualTest::values_squared(int a_, int b_)
176{
177 return (a_ * a_ == b_);
178}
_STLP_MOVE_TO_STD_NAMESPACE _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algo.h:507
_STLP_MOVE_TO_STD_NAMESPACE pair< _ForwardIter, _ForwardIter > equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algo.h:535
_STLP_MOVE_TO_STD_NAMESPACE _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algo.h:481
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST(equal_range1)
void equal0()
Definition: equal_test.cpp:129
void equal_range0()
Definition: equal_test.cpp:41
void equal_range2()
Definition: equal_test.cpp:90
CPPUNIT_TEST(equal2)
static bool values_squared(int a_, int b_)
Definition: equal_test.cpp:175
void equal2()
Definition: equal_test.cpp:151
CPPUNIT_TEST(equal_range2)
void equal1()
Definition: equal_test.cpp:139
CPPUNIT_TEST(equal0)
CPPUNIT_TEST(equal_range0)
CPPUNIT_TEST(equalto)
void equal_range1()
Definition: equal_test.cpp:49
void equalto()
Definition: equal_test.cpp:162
CPPUNIT_TEST_SUITE(EqualTest)
CPPUNIT_TEST(equal1)
Test(int val)
Definition: equal_test.cpp:72
int value
Definition: equal_test.cpp:73
bool operator==(int i) const
Definition: equal_test.cpp:75
#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
bool operator<(const Test &v1, int v2)
Definition: equal_test.cpp:79
const GLdouble * v
Definition: gl.h:2040
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLenum GLenum transform
Definition: glext.h:9407
GLenum GLint * range
Definition: glext.h:7539
GLuint GLfloat * val
Definition: glext.h:7180
GLfloat GLfloat p
Definition: glext.h:8902
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
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
#define equal(x, y)
Definition: reader.cc:56
Definition: _pair.h:47
value_type * iterator
Definition: _vector.h:124
Definition: pdh_main.c:94