31
|
1 |
|
|
2 |
|
|
3 |
// STLport regression testsuite component.
|
|
4 |
// To compile as a separate example, please #define MAIN.
|
|
5 |
|
|
6 |
#include <iostream>
|
|
7 |
#include <vector>
|
|
8 |
#include <algorithm>
|
|
9 |
|
|
10 |
#ifdef MAIN
|
|
11 |
#define vec7_test main
|
|
12 |
#endif
|
|
13 |
|
|
14 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
15 |
using namespace std;
|
|
16 |
#endif
|
|
17 |
int vec7_test(int, char**)
|
|
18 |
{
|
|
19 |
int failures=0;
|
|
20 |
cout<<"Results of vec7_test:"<<endl;
|
|
21 |
int array1 [] = { 1, 4, 25 };
|
|
22 |
int array2 [] = { 9, 16 };
|
|
23 |
|
|
24 |
vector<int> v(array1, array1 + 3);
|
|
25 |
v.insert(v.begin(), 0); // Insert before first element.
|
|
26 |
v.insert(v.end(), 36); // Insert after last element.
|
|
27 |
int i;
|
|
28 |
for(i = 0; i < v.size(); i++)
|
|
29 |
cout << "v[" << i << "] = " << v[i] << endl;
|
|
30 |
cout << endl;
|
|
31 |
|
|
32 |
if(0!=v[0])
|
|
33 |
failures++;
|
|
34 |
else if(1!=v[1])
|
|
35 |
failures++;
|
|
36 |
else if(4!=v[2])
|
|
37 |
failures++;
|
|
38 |
else if(25!=v[3])
|
|
39 |
failures++;
|
|
40 |
else if(36!=v[4])
|
|
41 |
failures++;
|
|
42 |
|
|
43 |
// Insert contents of array2 before fourth element.
|
|
44 |
v.insert(v.begin() + 3, array2, array2 + 2);
|
|
45 |
for(i = 0; i < v.size(); i++)
|
|
46 |
cout << "v[" << i << "] = " << v[i] << endl;
|
|
47 |
|
|
48 |
if(0!=v[0])
|
|
49 |
failures++;
|
|
50 |
else if(1!=v[1])
|
|
51 |
failures++;
|
|
52 |
else if(4!=v[2])
|
|
53 |
failures++;
|
|
54 |
else if(9!=v[3])
|
|
55 |
failures++;
|
|
56 |
else if(16!=v[4])
|
|
57 |
failures++;
|
|
58 |
else if(25!=v[5])
|
|
59 |
failures++;
|
|
60 |
else if(36!=v[6])
|
|
61 |
failures++;
|
|
62 |
|
|
63 |
cout << endl;
|
|
64 |
|
|
65 |
if(failures)
|
|
66 |
return 1;
|
|
67 |
else
|
|
68 |
return 0;
|
|
69 |
}
|
|
70 |
|
|
71 |
/*Results of vec7_test:
|
|
72 |
v[0] = 0
|
|
73 |
v[1] = 1
|
|
74 |
v[2] = 4
|
|
75 |
v[3] = 25
|
|
76 |
v[4] = 36
|
|
77 |
|
|
78 |
v[0] = 0
|
|
79 |
v[1] = 1
|
|
80 |
v[2] = 4
|
|
81 |
v[3] = 9
|
|
82 |
v[4] = 16
|
|
83 |
v[5] = 25
|
|
84 |
v[6] = 36
|
|
85 |
*/
|