|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <numeric> |
|
18 #include <string> |
|
19 #include <iterator> |
|
20 #include <vector> |
|
21 #include <algorithm> |
|
22 #include <functional> |
|
23 |
|
24 #include "iota.h" |
|
25 #include "cppunit/cppunit_proxy.h" |
|
26 |
|
27 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) |
|
28 using namespace std; |
|
29 #endif |
|
30 |
|
31 // |
|
32 // TestCase class |
|
33 // |
|
34 class SetIntersectionTest : public CPPUNIT_NS::TestCase |
|
35 { |
|
36 CPPUNIT_TEST_SUITE(SetIntersectionTest); |
|
37 CPPUNIT_TEST(setintr0); |
|
38 CPPUNIT_TEST(setintr1); |
|
39 CPPUNIT_TEST(setintr2); |
|
40 CPPUNIT_TEST_SUITE_END(); |
|
41 |
|
42 protected: |
|
43 void setintr0(); |
|
44 void setintr1(); |
|
45 void setintr2(); |
|
46 }; |
|
47 |
|
48 CPPUNIT_TEST_SUITE_REGISTRATION(SetIntersectionTest); |
|
49 |
|
50 // |
|
51 // tests implementation |
|
52 // |
|
53 void SetIntersectionTest::setintr0() |
|
54 { |
|
55 int v1[3] = { 13, 18, 23 }; |
|
56 int v2[4] = { 10, 13, 17, 23 }; |
|
57 int result[4] = { 0, 0, 0, 0 }; |
|
58 |
|
59 set_intersection((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result); |
|
60 |
|
61 CPPUNIT_ASSERT(result[0]==13); |
|
62 CPPUNIT_ASSERT(result[1]==23); |
|
63 CPPUNIT_ASSERT(result[2]==0); |
|
64 CPPUNIT_ASSERT(result[3]==0); |
|
65 } |
|
66 |
|
67 void SetIntersectionTest::setintr1() |
|
68 { |
|
69 vector <int> v1(10); |
|
70 __iota(v1.begin(), v1.end(), 0); |
|
71 vector <int> v2(10); |
|
72 __iota(v2.begin(), v2.end(), 7); |
|
73 |
|
74 vector<int> inter; |
|
75 set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(inter)); |
|
76 CPPUNIT_ASSERT( inter.size() == 3 ); |
|
77 CPPUNIT_ASSERT( inter[0] == 7 ); |
|
78 CPPUNIT_ASSERT( inter[1] == 8 ); |
|
79 CPPUNIT_ASSERT( inter[2] == 9 ); |
|
80 } |
|
81 |
|
82 void SetIntersectionTest::setintr2() |
|
83 { |
|
84 char* word1 = "ABCDEFGHIJKLMNO"; |
|
85 char* word2 = "LMNOPQRSTUVWXYZ"; |
|
86 |
|
87 string inter; |
|
88 set_intersection(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), |
|
89 back_inserter(inter), less<char>()); |
|
90 CPPUNIT_ASSERT( inter.size() == 4 ); |
|
91 CPPUNIT_ASSERT( inter[0] == 'L' ); |
|
92 CPPUNIT_ASSERT( inter[1] == 'M' ); |
|
93 CPPUNIT_ASSERT( inter[2] == 'N' ); |
|
94 CPPUNIT_ASSERT( inter[3] == 'O' ); |
|
95 } |