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 <cstdlib>
|
|
8 |
#include <iterator>
|
|
9 |
#include <iostream>
|
|
10 |
#include <fstream>
|
|
11 |
|
|
12 |
#ifdef MAIN
|
|
13 |
#define nthelem1_test main
|
|
14 |
#endif
|
|
15 |
|
|
16 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
17 |
using namespace std;
|
|
18 |
#endif
|
|
19 |
int nthelem1_test(int, char**)
|
|
20 |
{
|
|
21 |
ofstream Outfile("c:\\nthelem1.txt");
|
|
22 |
cout<<"Results of nthelem1_test:"<<endl;
|
|
23 |
vector <int> v1(10) ;
|
|
24 |
int failures = 0;
|
|
25 |
v1[0] = 23;
|
|
26 |
v1[1] = 6;
|
|
27 |
v1[2] = 7;
|
|
28 |
v1[3] = 5;
|
|
29 |
v1[4] = 3;
|
|
30 |
v1[5] = 5;
|
|
31 |
v1[6] = 6;
|
|
32 |
v1[7] = 2;
|
|
33 |
v1[8] = 9;
|
|
34 |
v1[9] = 1;
|
|
35 |
|
|
36 |
/*for(int i = 0; i < v1.size(); i++)
|
|
37 |
v1[i] = rand() % 10;*/
|
|
38 |
|
|
39 |
ostream_iterator<int> iter(cout, " ");
|
|
40 |
ostream_iterator<int> iterfile(Outfile, " ");
|
|
41 |
copy(v1.begin(), v1.end(), iter);
|
|
42 |
copy(v1.begin(), v1.end(), iterfile);
|
|
43 |
cout << endl;
|
|
44 |
Outfile << endl;
|
|
45 |
|
|
46 |
|
|
47 |
nth_element(v1.begin(),
|
|
48 |
v1.begin() + v1.size() / 2,
|
|
49 |
v1.end());
|
|
50 |
copy(v1.begin(), v1.end(), iter);
|
|
51 |
copy(v1.begin(), v1.end(), iterfile);
|
|
52 |
cout << endl;
|
|
53 |
Outfile << endl;
|
|
54 |
Outfile <<v1[0]<<endl;
|
|
55 |
Outfile <<v1[1]<<endl;
|
|
56 |
Outfile <<v1[2]<<endl;
|
|
57 |
Outfile <<v1[3]<<endl;
|
|
58 |
Outfile <<v1[4]<<endl;
|
|
59 |
Outfile <<v1[5]<<endl;
|
|
60 |
Outfile <<v1[6]<<endl;
|
|
61 |
Outfile <<v1[7]<<endl;
|
|
62 |
Outfile <<v1[8]<<endl;
|
|
63 |
Outfile <<v1[9]<<endl;
|
|
64 |
if(v1[0] != 1)
|
|
65 |
failures++;
|
|
66 |
if(v1[1] != 2)
|
|
67 |
failures++;
|
|
68 |
if(v1[2] != 5)
|
|
69 |
failures++;
|
|
70 |
if(v1[3] != 3)
|
|
71 |
failures++;
|
|
72 |
if(v1[4] != 5)
|
|
73 |
failures++;
|
|
74 |
if(v1[5] != 6)
|
|
75 |
failures++;
|
|
76 |
if(v1[6] != 6)
|
|
77 |
failures++;
|
|
78 |
if(v1[7] != 7)
|
|
79 |
failures++;
|
|
80 |
if(v1[8] != 9)
|
|
81 |
failures++;
|
|
82 |
if(v1[9] != 23)
|
|
83 |
failures++;
|
|
84 |
|
|
85 |
Outfile.close();
|
|
86 |
return failures;
|
|
87 |
}
|