MCPcopy Create free account
hub / github.com/catboost/catboost / Test7

Method Test7

util/generic/vector_ut.cpp:250–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248 }
249
250 void Test7() {
251 int array1[] = {1, 4, 25};
252 int array2[] = {9, 16};
253
254 TVector<int> v(array1, array1 + 3);
255 TVector<int>::iterator vit;
256 vit = v.insert(v.begin(), 0); // Insert before first element.
257 UNIT_ASSERT(*vit == 0);
258
259 vit = v.insert(v.end(), 36); // Insert after last element.
260 UNIT_ASSERT(*vit == 36);
261
262 UNIT_ASSERT(v.size() == 5);
263 UNIT_ASSERT(v[0] == 0);
264 UNIT_ASSERT(v[1] == 1);
265 UNIT_ASSERT(v[2] == 4);
266 UNIT_ASSERT(v[3] == 25);
267 UNIT_ASSERT(v[4] == 36);
268
269 // Insert contents of array2 before fourth element.
270 v.insert(v.begin() + 3, array2, array2 + 2);
271
272 UNIT_ASSERT(v.size() == 7);
273
274 UNIT_ASSERT(v[0] == 0);
275 UNIT_ASSERT(v[1] == 1);
276 UNIT_ASSERT(v[2] == 4);
277 UNIT_ASSERT(v[3] == 9);
278 UNIT_ASSERT(v[4] == 16);
279 UNIT_ASSERT(v[5] == 25);
280 UNIT_ASSERT(v[6] == 36);
281
282 size_t curCapacity = v.capacity();
283 v.clear();
284 UNIT_ASSERT(v.empty());
285
286 // check that clear save reserved data
287 UNIT_ASSERT_EQUAL(curCapacity, v.capacity());
288
289 v.insert(v.begin(), 5, 10);
290 UNIT_ASSERT(v.size() == 5);
291 UNIT_ASSERT(v[0] == 10);
292 UNIT_ASSERT(v[1] == 10);
293 UNIT_ASSERT(v[2] == 10);
294 UNIT_ASSERT(v[3] == 10);
295 UNIT_ASSERT(v[4] == 10);
296 }
297
298 struct TestStruct {
299 unsigned int a[3];

Callers

nothing calls this directly

Calls 7

insertMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
capacityMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected