ReactOS  0.4.13-dev-39-g8b6696f
setinter_test.cpp
Go to the documentation of this file.
1 #include <numeric>
2 #include <string>
3 #include <iterator>
4 #include <vector>
5 #include <algorithm>
6 #include <functional>
7 
8 #include "iota.h"
10 
11 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
12 using namespace std;
13 #endif
14 
15 //
16 // TestCase class
17 //
18 class SetIntersectionTest : public CPPUNIT_NS::TestCase
19 {
21  CPPUNIT_TEST(setintr0);
22  CPPUNIT_TEST(setintr1);
23  CPPUNIT_TEST(setintr2);
25 
26 protected:
27  void setintr0();
28  void setintr1();
29  void setintr2();
30 };
31 
33 
34 //
35 // tests implementation
36 //
38 {
39  int v1[3] = { 13, 18, 23 };
40  int v2[4] = { 10, 13, 17, 23 };
41  int result[4] = { 0, 0, 0, 0 };
42 
43  set_intersection((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result);
44 
45  CPPUNIT_ASSERT(result[0]==13);
46  CPPUNIT_ASSERT(result[1]==23);
47  CPPUNIT_ASSERT(result[2]==0);
48  CPPUNIT_ASSERT(result[3]==0);
49 }
50 
52 {
53  vector <int> v1(10);
54  __iota(v1.begin(), v1.end(), 0);
55  vector <int> v2(10);
56  __iota(v2.begin(), v2.end(), 7);
57 
58  vector<int> inter;
59  set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(inter));
60  CPPUNIT_ASSERT( inter.size() == 3 );
61  CPPUNIT_ASSERT( inter[0] == 7 );
62  CPPUNIT_ASSERT( inter[1] == 8 );
63  CPPUNIT_ASSERT( inter[2] == 9 );
64 }
65 
67 {
68  const char* word1 = "ABCDEFGHIJKLMNO";
69  const char* word2 = "LMNOPQRSTUVWXYZ";
70 
71  string inter;
72  set_intersection(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2),
73  back_inserter(inter), less<char>());
74  CPPUNIT_ASSERT( inter.size() == 4 );
75  CPPUNIT_ASSERT( inter[0] == 'L' );
76  CPPUNIT_ASSERT( inter[1] == 'M' );
77  CPPUNIT_ASSERT( inter[2] == 'N' );
78  CPPUNIT_ASSERT( inter[3] == 'O' );
79 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void __iota(_It __first, _It __last, _Tp __val)
Definition: iota.h:8
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
back_insert_iterator< _Container > _STLP_CALL back_inserter(_Container &__x)
Definition: _iterator.h:187
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
CPPUNIT_TEST_SUITE_REGISTRATION(SetIntersectionTest)
_STLP_MOVE_TO_STD_NAMESPACE _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _OutputIter __result)
Definition: _algo.c:1689
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
GLuint64EXT * result
Definition: glext.h:11304
GLfloat GLfloat v1
Definition: glext.h:6062