31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <iostream>
|
|
6 |
#include <vector>
|
|
7 |
#include <algorithm>
|
|
8 |
|
|
9 |
#ifdef MAIN
|
|
10 |
#define vec2_test main
|
|
11 |
#endif
|
|
12 |
|
|
13 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
14 |
using namespace std;
|
|
15 |
#endif
|
|
16 |
|
|
17 |
static void print(vector<double>& vector_)
|
|
18 |
{
|
|
19 |
for(int i = 0; i < vector_.size(); i++)
|
|
20 |
cout << vector_[i] << " ";
|
|
21 |
cout << endl;
|
|
22 |
}
|
|
23 |
|
|
24 |
int vec2_test(int, char**)
|
|
25 |
{
|
|
26 |
int failures=0;
|
|
27 |
cout<<"Results of vec2_test:"<<endl;
|
|
28 |
|
|
29 |
vector<double> v1; // Empty vector of doubles.
|
|
30 |
v1.push_back(32.1);
|
|
31 |
v1.push_back(40.5);
|
|
32 |
vector<double> v2; // Another empty vector of doubles.
|
|
33 |
v2.push_back(3.56);
|
|
34 |
cout << "v1 = ";
|
|
35 |
print(v1);
|
|
36 |
cout << "v2 = ";
|
|
37 |
print(v2);
|
|
38 |
|
|
39 |
if(32.1!=v1[0])
|
|
40 |
failures++;
|
|
41 |
else if(40.5 !=v1[1])
|
|
42 |
failures++;
|
|
43 |
else if(3.56 !=v2[0])
|
|
44 |
failures++;
|
|
45 |
|
|
46 |
v1.swap(v2); // Swap the vector's contents.
|
|
47 |
cout << "v1 = ";
|
|
48 |
print(v1);
|
|
49 |
cout << "v2 = ";
|
|
50 |
print(v2);
|
|
51 |
|
|
52 |
if(32.1!=v2[0])
|
|
53 |
failures++;
|
|
54 |
else if(40.5 !=v2[1])
|
|
55 |
failures++;
|
|
56 |
else if(3.56 !=v1[0])
|
|
57 |
failures++;
|
|
58 |
|
|
59 |
v2 = v1; // Assign one vector to another.
|
|
60 |
cout << "v2 = ";
|
|
61 |
print(v2);
|
|
62 |
|
|
63 |
if(3.56!=v2[0])
|
|
64 |
failures++;
|
|
65 |
|
|
66 |
if(failures)
|
|
67 |
return 1;
|
|
68 |
else
|
|
69 |
return 0;
|
|
70 |
}
|
|
71 |
|
|
72 |
/*Results of vec2_test:
|
|
73 |
v1 = 32.1 40.5
|
|
74 |
v2 = 3.56
|
|
75 |
|
|
76 |
v1 = 3.56
|
|
77 |
v2 = 32.1 40.5
|
|
78 |
|
|
79 |
v2 = 3.56
|
|
80 |
*/
|