[CMAKE]
[reactos.git] / lib / 3rdparty / stlport / test / unit / setinter_test.cpp
1 #include <numeric>
2 #include <string>
3 #include <iterator>
4 #include <vector>
5 #include <algorithm>
6 #include <functional>
7
8 #include "iota.h"
9 #include "cppunit/cppunit_proxy.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 {
20 CPPUNIT_TEST_SUITE(SetIntersectionTest);
21 CPPUNIT_TEST(setintr0);
22 CPPUNIT_TEST(setintr1);
23 CPPUNIT_TEST(setintr2);
24 CPPUNIT_TEST_SUITE_END();
25
26 protected:
27 void setintr0();
28 void setintr1();
29 void setintr2();
30 };
31
32 CPPUNIT_TEST_SUITE_REGISTRATION(SetIntersectionTest);
33
34 //
35 // tests implementation
36 //
37 void SetIntersectionTest::setintr0()
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
51 void SetIntersectionTest::setintr1()
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
66 void SetIntersectionTest::setintr2()
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 }