ReactOS 0.4.16-dev-125-g798ea90
unique_test.cpp
Go to the documentation of this file.
1#include <algorithm>
2
4
5#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
6using namespace std;
7#endif
8
9//
10// TestCase class
11//
12class UniqueTest : public CPPUNIT_NS::TestCase
13{
20
21protected:
22 void uniqcpy1();
23 void uniqcpy2();
24 void unique1();
25 void unique2();
26};
27
29
30static bool str_equal(const char* a_, const char* b_)
31{ return *a_ == *b_; }
32//
33// tests implementation
34//
36{
37 int numbers[8] = { 0, 1, 1, 2, 2, 2, 3, 4 };
38 unique((int*)numbers, (int*)numbers + 8);
39 // 0 1 2 3 4 2 3 4
40 CPPUNIT_ASSERT(numbers[0]==0);
41 CPPUNIT_ASSERT(numbers[1]==1);
42 CPPUNIT_ASSERT(numbers[2]==2);
43 CPPUNIT_ASSERT(numbers[3]==3);
44 CPPUNIT_ASSERT(numbers[4]==4);
45 CPPUNIT_ASSERT(numbers[5]==2);
46 CPPUNIT_ASSERT(numbers[6]==3);
47 CPPUNIT_ASSERT(numbers[7]==4);
48}
49
51{
52 const char* labels[] = {"Q", "Q", "W", "W", "E", "E", "R", "T", "T", "Y", "Y"};
53
54 const unsigned count = sizeof(labels) / sizeof(labels[0]);
55
56 unique((const char**)labels, (const char**)labels + count, str_equal);
57
58 // QWERTY
59 CPPUNIT_ASSERT(*labels[0] == 'Q');
60 CPPUNIT_ASSERT(*labels[1] == 'W');
61 CPPUNIT_ASSERT(*labels[2] == 'E');
62 CPPUNIT_ASSERT(*labels[3] == 'R');
63 CPPUNIT_ASSERT(*labels[4] == 'T');
64 CPPUNIT_ASSERT(*labels[5] == 'Y');
65
66}
67
69{
70 int numbers[8] = { 0, 1, 1, 2, 2, 2, 3, 4 };
71 int result[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
72
73 unique_copy((int*)numbers, (int*)numbers + 8, (int*)result);
74
75 // 0 1 2 3 4 0 0 0
84}
85
87{
88 const char* labels[] = {"Q", "Q", "W", "W", "E", "E", "R", "T", "T", "Y", "Y"};
89 const char **plabels = (const char**)labels;
90
91 const size_t count = sizeof(labels) / sizeof(labels[0]);
92 const char* uCopy[count];
93 const char **puCopy = &uCopy[0];
94 fill(puCopy, puCopy + count, "");
95
96 unique_copy(plabels, plabels + count, puCopy, str_equal);
97
98 //QWERTY
99 CPPUNIT_ASSERT(*uCopy[0] == 'Q');
100 CPPUNIT_ASSERT(*uCopy[1] == 'W');
101 CPPUNIT_ASSERT(*uCopy[2] == 'E');
102 CPPUNIT_ASSERT(*uCopy[3] == 'R');
103 CPPUNIT_ASSERT(*uCopy[4] == 'T');
104 CPPUNIT_ASSERT(*uCopy[5] == 'Y');
105}
_STLP_MOVE_TO_STD_NAMESPACE _OutputIter unique_copy(_InputIter __first, _InputIter __last, _OutputIter __result)
Definition: _algo.c:348
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
CPPUNIT_TEST_SUITE(UniqueTest)
void unique1()
Definition: unique_test.cpp:35
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST(uniqcpy2)
CPPUNIT_TEST(unique2)
void uniqcpy1()
Definition: unique_test.cpp:68
void uniqcpy2()
Definition: unique_test.cpp:86
CPPUNIT_TEST(unique1)
CPPUNIT_TEST(uniqcpy1)
void unique2()
Definition: unique_test.cpp:50
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint64EXT * result
Definition: glext.h:11304
Definition: features.h:417
static bool str_equal(const char *a_, const char *b_)
Definition: unique_test.cpp:30