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