31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <vector>
|
|
6 |
#include <algorithm>
|
|
7 |
#include <functional>
|
|
8 |
#include <iterator>
|
|
9 |
#include <iostream>
|
|
10 |
|
|
11 |
#ifdef MAIN
|
|
12 |
#define merge2_test main
|
|
13 |
#endif
|
|
14 |
|
|
15 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
16 |
using namespace std;
|
|
17 |
#endif
|
|
18 |
int merge2_test(int, char**)
|
|
19 |
{
|
|
20 |
cout<<"Results of merge2_test:"<<endl;
|
|
21 |
vector <int> v1(5);
|
|
22 |
vector <int> v2(v1.size());
|
|
23 |
int failures = 0;
|
|
24 |
for(int i = 0; i < v1.size(); i++)
|
|
25 |
{
|
|
26 |
v1[i] = 10 - i;
|
|
27 |
v2[i] = 7 - i;
|
|
28 |
}
|
|
29 |
vector <int> result(v1.size() + v2.size());
|
|
30 |
merge(v1.begin(), v1.end(),
|
|
31 |
v2.begin(), v2.end(),
|
|
32 |
result.begin(),
|
|
33 |
greater<int>() );
|
|
34 |
ostream_iterator <int> iter(cout, " ");
|
|
35 |
copy(v1.begin(), v1.end(), iter);
|
|
36 |
cout << endl;
|
|
37 |
copy(v2.begin(), v2.end(), iter);
|
|
38 |
cout << endl;
|
|
39 |
copy(result.begin(), result.end(), iter);
|
|
40 |
cout << endl;
|
|
41 |
if (result[0] != 10)
|
|
42 |
failures++;
|
|
43 |
if (result[1] != 9)
|
|
44 |
failures++;
|
|
45 |
if (result[2] != 8)
|
|
46 |
failures++;
|
|
47 |
if (result[3] != 7)
|
|
48 |
failures++;
|
|
49 |
if (result[4] != 7)
|
|
50 |
failures++;
|
|
51 |
if (result[5] != 6)
|
|
52 |
failures++;
|
|
53 |
if (result[6] != 6)
|
|
54 |
failures++;
|
|
55 |
if (result[7] != 5)
|
|
56 |
failures++;
|
|
57 |
if (result[8] != 4)
|
|
58 |
failures++;
|
|
59 |
if (result[9] != 3)
|
|
60 |
failures++;
|
|
61 |
|
|
62 |
return failures;
|
|
63 |
}
|