ReactOS 0.4.16-dev-306-g647d351
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)
12using namespace std;
13#endif
14
15//
16// TestCase class
17//
18class SetIntersectionTest : public CPPUNIT_NS::TestCase
19{
25
26protected:
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);
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}
_STLP_MOVE_TO_STD_NAMESPACE _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _OutputIter __result)
Definition: _algo.c:1689
back_insert_iterator< _Container > _STLP_CALL back_inserter(_Container &__x)
Definition: _iterator.h:187
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
CPPUNIT_TEST_SUITE(SetIntersectionTest)
CPPUNIT_TEST(setintr1)
CPPUNIT_TEST(setintr0)
CPPUNIT_TEST(setintr2)
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLfloat GLfloat v1
Definition: glext.h:6062
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
GLuint64EXT * result
Definition: glext.h:11304
void __iota(_It __first, _It __last, _Tp __val)
Definition: iota.h:8
Definition: features.h:417