|
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 |
|
18 // STLport regression testsuite component. |
|
19 // To compile as a separate example, please #define MAIN. |
|
20 #include <iterator> |
|
21 |
|
22 #include <algorithm> |
|
23 #include <vector> |
|
24 #include <iostream> |
|
25 #include <iterator> |
|
26 // #include <functional> |
|
27 #include <numeric> |
|
28 |
|
29 #ifdef MAIN |
|
30 #define search1_test main |
|
31 #endif |
|
32 |
|
33 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES) |
|
34 using namespace std; |
|
35 #endif |
|
36 int search1_test(int, char**) |
|
37 { |
|
38 int failures=0; |
|
39 cout<<"Results of search1_test:"<<endl; |
|
40 typedef vector <int> IntVec; |
|
41 IntVec v1(10); |
|
42 iota(v1.begin(), v1.end(), 0); |
|
43 IntVec v2(3); |
|
44 iota(v2.begin(), v2.end(), 50); |
|
45 ostream_iterator <int> iter(cout, " "); |
|
46 |
|
47 cout << "v1: "; |
|
48 copy(v1.begin(), v1.end(), iter); |
|
49 cout << endl; |
|
50 |
|
51 if(0!=v1[0]) |
|
52 failures++; |
|
53 else if(1!=v1[1]) |
|
54 failures++; |
|
55 else if(2!=v1[2]) |
|
56 failures++; |
|
57 else if(3!=v1[3]) |
|
58 failures++; |
|
59 else if(4!=v1[4]) |
|
60 failures++; |
|
61 else if(5!=v1[5]) |
|
62 failures++; |
|
63 else if(6!=v1[6]) |
|
64 failures++; |
|
65 else if(7!=v1[7]) |
|
66 failures++; |
|
67 else if(8!=v1[8]) |
|
68 failures++; |
|
69 else if(9!=v1[9]) |
|
70 failures++; |
|
71 |
|
72 cout << "v2: "; |
|
73 copy(v2.begin(), v2.end(), iter); |
|
74 cout << endl; |
|
75 |
|
76 if(50!=v2[0]) |
|
77 failures++; |
|
78 else if(51!=v2[1]) |
|
79 failures++; |
|
80 else if(52!=v2[2]) |
|
81 failures++; |
|
82 |
|
83 IntVec::iterator location; |
|
84 location = search(v1.begin(), v1.end(), v2.begin(), v2.end()); |
|
85 |
|
86 if(location == v1.end()) |
|
87 cout << "v2 not contained in v1" << endl; |
|
88 else |
|
89 cout << "Found v2 in v1 at offset: " << location - v1.begin() << endl; |
|
90 |
|
91 if(location !=v1.end()) |
|
92 failures++; |
|
93 |
|
94 iota(v2.begin(), v2.end(), 4); |
|
95 cout << "v1: "; |
|
96 copy(v1.begin(), v1.end(), iter); |
|
97 cout << endl; |
|
98 |
|
99 if(0!=v1[0]) |
|
100 failures++; |
|
101 else if(1!=v1[1]) |
|
102 failures++; |
|
103 else if(2!=v1[2]) |
|
104 failures++; |
|
105 else if(3!=v1[3]) |
|
106 failures++; |
|
107 else if(4!=v1[4]) |
|
108 failures++; |
|
109 else if(5!=v1[5]) |
|
110 failures++; |
|
111 else if(6!=v1[6]) |
|
112 failures++; |
|
113 else if(7!=v1[7]) |
|
114 failures++; |
|
115 else if(8!=v1[8]) |
|
116 failures++; |
|
117 else if(9!=v1[9]) |
|
118 failures++; |
|
119 |
|
120 cout << "v2: "; |
|
121 copy(v2.begin(), v2.end(), iter); |
|
122 cout << endl; |
|
123 |
|
124 if(4!=v2[0]) |
|
125 failures++; |
|
126 else if(5!=v2[1]) |
|
127 failures++; |
|
128 else if(6!=v2[2]) |
|
129 failures++; |
|
130 |
|
131 location = search(v1.begin(), v1.end(), v2.begin(), v2.end()); |
|
132 |
|
133 if(location == v1.end()) |
|
134 cout << "v2 not contained in v1" << endl; |
|
135 else |
|
136 cout << "Found v2 in v1 at offset: " << location - v1.begin() << endl; |
|
137 |
|
138 if(location ==v1.end()) |
|
139 failures++; |
|
140 |
|
141 if(failures) |
|
142 return 1; |
|
143 else |
|
144 return 0; |
|
145 } |
|
146 |