-
Notifications
You must be signed in to change notification settings - Fork 0
/
orig_vector_test.cpp
207 lines (186 loc) · 5.1 KB
/
orig_vector_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <iostream>
#include <vector>
void range_constructor(void)
{
std::cout << "\n\n--- RANGE CONSTRUCTOR TESTS ---\n";
std::vector<int> v(4, 42);
std::vector<int> v2(v.begin(), v.end());
std::vector<int> v3(int, float);
std::cout << "v.size(): " << v.size() << "\n";
std::cout << "v2.size(): " << v2.size() << "\n";
std::cout << "v.capacity(): " << v.capacity() << "\n";
std::cout << "v2.capacity(): " << v2.capacity() << "\n";
//std::cout << "v3.size(): " << v3.size() << "\n";
std::cout << "v.front() " << v.front() << "\n";
std::cout << "v2.front()" << v2.front() << "\n";
return ;
}
void iterator(void)
{
std::cout << "\n\n--- ITERATOR TESTS ---\n";
std::vector<int> v;
std::vector<int>::iterator it;
it = v.begin();
if (it == v.begin())
std::cout << "Equal\n";
it = v.end();
if (it == v.begin())
std::cout << "Equal\n";
//std::cout << "end value: " << *it << std::endl;
return ;
}
void iterator_2(void)
{
std::cout << "\n\n--- ITERATOR_2 TESTS ---\n";
std::vector<int> v(5, 1);
std::vector<int>::iterator it;
it = v.begin();
*it = 42;
std::cout << "*it: " << *it << "\n";
std::cout << "*it++: " << *it++ << "\n";
std::cout << "*it: " << *it << "\n";
it = v.begin();
std::cout << *it << "\n";
--it;
std::cout << *it << "\n";
--it;
std::cout << *it << "\n";
std::cout << "v[-1]: " << v[-1] << "\n";
std::cout << "v[-2]: " << v[-2] << "\n";
return ;
}
void iterator_3(void)
{
std::cout << "\n\n--- ITERATOR_3 TESTS ---\n";
std::vector<int> v(5, 1);
std::vector<int>::iterator it;
std::vector<int>::iterator it2;
for (int i = 0; v.begin() + i != v.end(); ++i)
*(v.begin() + i) = i;
it = v.begin();
it2 = v.begin() + 2;
std::cout << *it << "\n";
std::cout << *(it + 1) << "\n";
std::cout << *it << "\n";
*(it + 1) = 42;
std::cout << v[1] << "\n";
it2 = it + 1;
std::cout << *it2 << "\n";
*(it + 1) = 1;
it2 = v.begin() + 3;
std::cout << "it2 - it: " << it2 - it << "\n";
*it = 24;
std::cout << "*(it -= 100): " << *(it -= 100) << "\n";
std::cout << *(it + 90) << "\n";
std::cout << *(it + 100) << "\n";
std::cout << it[100] << "\n";
return ;
}
void const_iter(void)
{
std::vector<int> v(2, 1);
std::vector<int>::iterator it;
std::vector<int>::const_iterator cit;
std::cout << "\n\n--- CONST ITERATOR TESTS ---\n";
it = v.begin();
cit = v.begin();
if (it == cit)
std::cout << "Equal\n";
if (cit == it)
std::cout << "Equal\n";
return ;
}
void iter_traits(void)
{
std::cout << "\n\n--- ITER TRAITS TESTS ---\n";
std::vector<int> v(2, 1);
std::vector<int>::iterator it;
it = v.begin();
return ;
}
void reverse_iter(void)
{
std::cout << "\n\n--- REVERSE ITERATOR TESTS ---\n";
std::vector<int> v(5, 0);
std::size_t i;
std::vector<int>::iterator it;
std::vector<int>::reverse_iterator rit(v.end());
std::vector<int>::reverse_iterator rit2(v.begin());
i = 0;
for (it = v.begin(); it != v.end(); ++it)
*it = i++;
for (; rit != rit2; ++rit)
std::cout << "value: " << *rit << " base: " << *(rit.base()) << "\n";
return ;
}
void push_pop(void)
{
std::cout << "\n\n--- PUSH POP TESTS ---\n";
std::vector<int> v(2, 100);
std::cout << "v.capacity(): " << v.capacity();
std::cout << " v.size(): " << v.size() << "\n";
std::cout << "v.back(): " << v.back() << "\n";
v.push_back(42);
std::cout << "EXECUTE v.push_back(42)" << "\n";
std::cout << "v.capacity(): " << v.capacity();
std::cout << " v.size(): " << v.size() << "\n";
std::cout << "v.back(): " << v.back() << "\n";
v.pop_back();
std::cout << "EXECUTE v.pop_back()" << "\n";
std::cout << "v.capacity(): " << v.capacity();
std::cout << " v.size(): " << v.size() << "\n";
std::cout << "v.back(): " << v.back() << "\n";
return ;
}
void insert(void)
{
std::cout << "\n\n--- INSERT TESTS ---\n";
std::vector<int> v(2, 100);
std::vector<int>::iterator it;
std::cout << "v.size(): " << v.size() << " v.capacity(): " << v.capacity() << "\n";
v.insert(v.end(), 2, 200);
std::cout << "v.size(): " << v.size() << " v.capacity(): " << v.capacity() << "\n";
for (it = v.begin(); it < v.end(); ++it)
{
std::cout << "index: " << it - v.begin() << " val: " << *it << "\n";
}
return ;
}
void non_member_relational(void)
{
std::cout << "\n\n--- RELATIONAL TESTS ---\n";
std::vector<int> v(2, 200);
std::vector<int> v2(v);
std::cout << "v(2, 200)\nv2(v)\n";
std::cout << std::boolalpha;
std::cout << "v == v2 ? " << (v == v2) << "\n";
std::cout << "v >= v2 ? " << (v >= v2) << "\n";
std::cout << "v != v2 ? " << (v != v2) << "\n";
v.back() = 201;
std::cout << "\nEXECUTED v.back() = 201\n\n";
std::cout << "v > v2 ? " << (v > v2) << "\n";
std::cout << "v < v2 ? " << (v < v2) << "\n";
v2.push_back(200);
std::cout << "\nEXECUTED v2.push_back(200)\n\n";
std::cout << "v > v2 ? " << (v > v2) << "\n";
std::cout << "v < v2 ? " << (v < v2) << "\n";
v.back() = 200;
std::cout << "\nEXECUTED v.back() = 200\n\n";
std::cout << "v > v2 ? " << (v > v2) << "\n";
std::cout << "v < v2 ? " << (v < v2) << "\n";
return ;
}
int main(void)
{
range_constructor();
iterator();
iterator_2();
iterator_3();
const_iter();
iter_traits();
reverse_iter();
push_pop();
insert();
non_member_relational();
return (0);
}