ReactOS  0.4.13-dev-79-gcd489d8
unique_test.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 
4 
5 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
6 using namespace std;
7 #endif
8 
9 //
10 // TestCase class
11 //
12 class UniqueTest : public CPPUNIT_NS::TestCase
13 {
15  CPPUNIT_TEST(uniqcpy1);
16  CPPUNIT_TEST(uniqcpy2);
17  CPPUNIT_TEST(unique1);
18  CPPUNIT_TEST(unique2);
20 
21 protected:
22  void uniqcpy1();
23  void uniqcpy2();
24  void unique1();
25  void unique2();
26 };
27 
29 
30 static 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
76  CPPUNIT_ASSERT(result[0]==0);
77  CPPUNIT_ASSERT(result[1]==1);
78  CPPUNIT_ASSERT(result[2]==2);
79  CPPUNIT_ASSERT(result[3]==3);
80  CPPUNIT_ASSERT(result[4]==4);
81  CPPUNIT_ASSERT(result[5]==0);
82  CPPUNIT_ASSERT(result[6]==0);
83  CPPUNIT_ASSERT(result[7]==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
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
void uniqcpy2()
Definition: unique_test.cpp:86
void unique2()
Definition: unique_test.cpp:50
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
CPPUNIT_TEST_SUITE_REGISTRATION(UniqueTest)
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
void unique1()
Definition: unique_test.cpp:35
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
_ForwardIter unique(_ForwardIter __first, _ForwardIter __last)
Definition: _algo.h:298
static bool str_equal(const char *a_, const char *b_)
Definition: unique_test.cpp:30
void uniqcpy1()
Definition: unique_test.cpp:68
GLuint64EXT * result
Definition: glext.h:11304