1 // Copyright (c) 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <utility>
16 #include <vector>
17
18 #include "gmock/gmock.h"
19 #include "source/util/small_vector.h"
20
21 namespace spvtools {
22 namespace utils {
23 namespace {
24
25 using SmallVectorTest = ::testing::Test;
26
TEST(SmallVectorTest,Initialize_default)27 TEST(SmallVectorTest, Initialize_default) {
28 SmallVector<uint32_t, 2> vec;
29
30 EXPECT_TRUE(vec.empty());
31 EXPECT_EQ(vec.size(), 0);
32 EXPECT_EQ(vec.begin(), vec.end());
33 }
34
TEST(SmallVectorTest,Initialize_list1)35 TEST(SmallVectorTest, Initialize_list1) {
36 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
37
38 EXPECT_FALSE(vec.empty());
39 EXPECT_EQ(vec.size(), 4);
40
41 uint32_t result[] = {0, 1, 2, 3};
42 for (uint32_t i = 0; i < vec.size(); ++i) {
43 EXPECT_EQ(vec[i], result[i]);
44 }
45 }
46
TEST(SmallVectorTest,Initialize_list2)47 TEST(SmallVectorTest, Initialize_list2) {
48 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
49
50 EXPECT_FALSE(vec.empty());
51 EXPECT_EQ(vec.size(), 4);
52
53 uint32_t result[] = {0, 1, 2, 3};
54 for (uint32_t i = 0; i < vec.size(); ++i) {
55 EXPECT_EQ(vec[i], result[i]);
56 }
57 }
58
TEST(SmallVectorTest,Initialize_copy1)59 TEST(SmallVectorTest, Initialize_copy1) {
60 SmallVector<uint32_t, 6> vec1 = {0, 1, 2, 3};
61 SmallVector<uint32_t, 6> vec2(vec1);
62
63 EXPECT_EQ(vec2.size(), 4);
64
65 uint32_t result[] = {0, 1, 2, 3};
66 for (uint32_t i = 0; i < vec2.size(); ++i) {
67 EXPECT_EQ(vec2[i], result[i]);
68 }
69
70 EXPECT_EQ(vec1, vec2);
71 }
72
TEST(SmallVectorTest,Initialize_copy2)73 TEST(SmallVectorTest, Initialize_copy2) {
74 SmallVector<uint32_t, 2> vec1 = {0, 1, 2, 3};
75 SmallVector<uint32_t, 2> vec2(vec1);
76
77 EXPECT_EQ(vec2.size(), 4);
78
79 uint32_t result[] = {0, 1, 2, 3};
80 for (uint32_t i = 0; i < vec2.size(); ++i) {
81 EXPECT_EQ(vec2[i], result[i]);
82 }
83
84 EXPECT_EQ(vec1, vec2);
85 }
86
TEST(SmallVectorTest,Initialize_copy_vec1)87 TEST(SmallVectorTest, Initialize_copy_vec1) {
88 std::vector<uint32_t> vec1 = {0, 1, 2, 3};
89 SmallVector<uint32_t, 6> vec2(vec1);
90
91 EXPECT_EQ(vec2.size(), 4);
92
93 uint32_t result[] = {0, 1, 2, 3};
94 for (uint32_t i = 0; i < vec2.size(); ++i) {
95 EXPECT_EQ(vec2[i], result[i]);
96 }
97
98 EXPECT_EQ(vec1, vec2);
99 }
100
TEST(SmallVectorTest,Initialize_copy_vec2)101 TEST(SmallVectorTest, Initialize_copy_vec2) {
102 std::vector<uint32_t> vec1 = {0, 1, 2, 3};
103 SmallVector<uint32_t, 2> vec2(vec1);
104
105 EXPECT_EQ(vec2.size(), 4);
106
107 uint32_t result[] = {0, 1, 2, 3};
108 for (uint32_t i = 0; i < vec2.size(); ++i) {
109 EXPECT_EQ(vec2[i], result[i]);
110 }
111
112 EXPECT_EQ(vec1, vec2);
113 }
114
TEST(SmallVectorTest,Initialize_move1)115 TEST(SmallVectorTest, Initialize_move1) {
116 SmallVector<uint32_t, 6> vec1 = {0, 1, 2, 3};
117 SmallVector<uint32_t, 6> vec2(std::move(vec1));
118
119 EXPECT_EQ(vec2.size(), 4);
120
121 uint32_t result[] = {0, 1, 2, 3};
122 for (uint32_t i = 0; i < vec2.size(); ++i) {
123 EXPECT_EQ(vec2[i], result[i]);
124 }
125 EXPECT_TRUE(vec1.empty());
126 }
127
TEST(SmallVectorTest,Initialize_move2)128 TEST(SmallVectorTest, Initialize_move2) {
129 SmallVector<uint32_t, 2> vec1 = {0, 1, 2, 3};
130 SmallVector<uint32_t, 2> vec2(std::move(vec1));
131
132 EXPECT_EQ(vec2.size(), 4);
133
134 uint32_t result[] = {0, 1, 2, 3};
135 for (uint32_t i = 0; i < vec2.size(); ++i) {
136 EXPECT_EQ(vec2[i], result[i]);
137 }
138 EXPECT_TRUE(vec1.empty());
139 }
140
TEST(SmallVectorTest,Initialize_move_vec1)141 TEST(SmallVectorTest, Initialize_move_vec1) {
142 std::vector<uint32_t> vec1 = {0, 1, 2, 3};
143 SmallVector<uint32_t, 6> vec2(std::move(vec1));
144
145 EXPECT_EQ(vec2.size(), 4);
146
147 uint32_t result[] = {0, 1, 2, 3};
148 for (uint32_t i = 0; i < vec2.size(); ++i) {
149 EXPECT_EQ(vec2[i], result[i]);
150 }
151 EXPECT_TRUE(vec1.empty());
152 }
153
TEST(SmallVectorTest,Initialize_move_vec2)154 TEST(SmallVectorTest, Initialize_move_vec2) {
155 std::vector<uint32_t> vec1 = {0, 1, 2, 3};
156 SmallVector<uint32_t, 2> vec2(std::move(vec1));
157
158 EXPECT_EQ(vec2.size(), 4);
159
160 uint32_t result[] = {0, 1, 2, 3};
161 for (uint32_t i = 0; i < vec2.size(); ++i) {
162 EXPECT_EQ(vec2[i], result[i]);
163 }
164 EXPECT_TRUE(vec1.empty());
165 }
166
TEST(SmallVectorTest,Initialize_iterators1)167 TEST(SmallVectorTest, Initialize_iterators1) {
168 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
169
170 EXPECT_EQ(vec.size(), 4);
171 uint32_t result[] = {0, 1, 2, 3};
172
173 uint32_t i = 0;
174 for (uint32_t p : vec) {
175 EXPECT_EQ(p, result[i]);
176 i++;
177 }
178 }
179
TEST(SmallVectorTest,Initialize_iterators2)180 TEST(SmallVectorTest, Initialize_iterators2) {
181 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
182
183 EXPECT_EQ(vec.size(), 4);
184 uint32_t result[] = {0, 1, 2, 3};
185
186 uint32_t i = 0;
187 for (uint32_t p : vec) {
188 EXPECT_EQ(p, result[i]);
189 i++;
190 }
191 }
192
TEST(SmallVectorTest,Initialize_iterators3)193 TEST(SmallVectorTest, Initialize_iterators3) {
194 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
195
196 EXPECT_EQ(vec.size(), 4);
197 uint32_t result[] = {0, 1, 2, 3};
198
199 uint32_t i = 0;
200 for (SmallVector<uint32_t, 2>::iterator it = vec.begin(); it != vec.end();
201 ++it) {
202 EXPECT_EQ(*it, result[i]);
203 i++;
204 }
205 }
206
TEST(SmallVectorTest,Initialize_iterators4)207 TEST(SmallVectorTest, Initialize_iterators4) {
208 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
209
210 EXPECT_EQ(vec.size(), 4);
211 uint32_t result[] = {0, 1, 2, 3};
212
213 uint32_t i = 0;
214 for (SmallVector<uint32_t, 6>::iterator it = vec.begin(); it != vec.end();
215 ++it) {
216 EXPECT_EQ(*it, result[i]);
217 i++;
218 }
219 }
220
TEST(SmallVectorTest,Initialize_iterators_write1)221 TEST(SmallVectorTest, Initialize_iterators_write1) {
222 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
223
224 EXPECT_EQ(vec.size(), 4);
225 for (SmallVector<uint32_t, 6>::iterator it = vec.begin(); it != vec.end();
226 ++it) {
227 *it *= 2;
228 }
229
230 uint32_t result[] = {0, 2, 4, 6};
231
232 uint32_t i = 0;
233 for (SmallVector<uint32_t, 6>::iterator it = vec.begin(); it != vec.end();
234 ++it) {
235 EXPECT_EQ(*it, result[i]);
236 i++;
237 }
238 }
239
TEST(SmallVectorTest,Initialize_iterators_write2)240 TEST(SmallVectorTest, Initialize_iterators_write2) {
241 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
242
243 EXPECT_EQ(vec.size(), 4);
244 for (SmallVector<uint32_t, 2>::iterator it = vec.begin(); it != vec.end();
245 ++it) {
246 *it *= 2;
247 }
248
249 uint32_t result[] = {0, 2, 4, 6};
250
251 uint32_t i = 0;
252 for (SmallVector<uint32_t, 2>::iterator it = vec.begin(); it != vec.end();
253 ++it) {
254 EXPECT_EQ(*it, result[i]);
255 i++;
256 }
257 }
258
TEST(SmallVectorTest,Initialize_front)259 TEST(SmallVectorTest, Initialize_front) {
260 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
261
262 EXPECT_EQ(vec.front(), 0);
263 for (SmallVector<uint32_t, 2>::iterator it = vec.begin(); it != vec.end();
264 ++it) {
265 *it += 2;
266 }
267 EXPECT_EQ(vec.front(), 2);
268 }
269
TEST(SmallVectorTest,Erase_element_front1)270 TEST(SmallVectorTest, Erase_element_front1) {
271 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
272
273 EXPECT_EQ(vec.front(), 0);
274 EXPECT_EQ(vec.size(), 4);
275 vec.erase(vec.begin());
276 EXPECT_EQ(vec.front(), 1);
277 EXPECT_EQ(vec.size(), 3);
278 }
279
TEST(SmallVectorTest,Erase_element_front2)280 TEST(SmallVectorTest, Erase_element_front2) {
281 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
282
283 EXPECT_EQ(vec.front(), 0);
284 EXPECT_EQ(vec.size(), 4);
285 vec.erase(vec.begin());
286 EXPECT_EQ(vec.front(), 1);
287 EXPECT_EQ(vec.size(), 3);
288 }
289
TEST(SmallVectorTest,Erase_element_back1)290 TEST(SmallVectorTest, Erase_element_back1) {
291 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
292 SmallVector<uint32_t, 2> result = {0, 1, 2};
293
294 EXPECT_EQ(vec[3], 3);
295 EXPECT_EQ(vec.size(), 4);
296 vec.erase(vec.begin() + 3);
297 EXPECT_EQ(vec.size(), 3);
298 EXPECT_EQ(vec, result);
299 }
300
TEST(SmallVectorTest,Erase_element_back2)301 TEST(SmallVectorTest, Erase_element_back2) {
302 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
303 SmallVector<uint32_t, 6> result = {0, 1, 2};
304
305 EXPECT_EQ(vec[3], 3);
306 EXPECT_EQ(vec.size(), 4);
307 vec.erase(vec.begin() + 3);
308 EXPECT_EQ(vec.size(), 3);
309 EXPECT_EQ(vec, result);
310 }
311
TEST(SmallVectorTest,Erase_element_middle1)312 TEST(SmallVectorTest, Erase_element_middle1) {
313 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
314 SmallVector<uint32_t, 2> result = {0, 1, 3};
315
316 EXPECT_EQ(vec.size(), 4);
317 vec.erase(vec.begin() + 2);
318 EXPECT_EQ(vec.size(), 3);
319 EXPECT_EQ(vec, result);
320 }
321
TEST(SmallVectorTest,Erase_element_middle2)322 TEST(SmallVectorTest, Erase_element_middle2) {
323 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
324 SmallVector<uint32_t, 6> result = {0, 1, 3};
325
326 EXPECT_EQ(vec.size(), 4);
327 vec.erase(vec.begin() + 2);
328 EXPECT_EQ(vec.size(), 3);
329 EXPECT_EQ(vec, result);
330 }
331
TEST(SmallVectorTest,Erase_range_1)332 TEST(SmallVectorTest, Erase_range_1) {
333 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
334 SmallVector<uint32_t, 6> result = {};
335
336 EXPECT_EQ(vec.size(), 4);
337 vec.erase(vec.begin(), vec.end());
338 EXPECT_EQ(vec.size(), 0);
339 EXPECT_EQ(vec, result);
340 }
341
TEST(SmallVectorTest,Erase_range_2)342 TEST(SmallVectorTest, Erase_range_2) {
343 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
344 SmallVector<uint32_t, 2> result = {};
345
346 EXPECT_EQ(vec.size(), 4);
347 vec.erase(vec.begin(), vec.end());
348 EXPECT_EQ(vec.size(), 0);
349 EXPECT_EQ(vec, result);
350 }
351
TEST(SmallVectorTest,Erase_range_3)352 TEST(SmallVectorTest, Erase_range_3) {
353 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
354 SmallVector<uint32_t, 6> result = {2, 3};
355
356 EXPECT_EQ(vec.size(), 4);
357 vec.erase(vec.begin(), vec.begin() + 2);
358 EXPECT_EQ(vec.size(), 2);
359 EXPECT_EQ(vec, result);
360 }
361
TEST(SmallVectorTest,Erase_range_4)362 TEST(SmallVectorTest, Erase_range_4) {
363 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
364 SmallVector<uint32_t, 2> result = {2, 3};
365
366 EXPECT_EQ(vec.size(), 4);
367 vec.erase(vec.begin(), vec.begin() + 2);
368 EXPECT_EQ(vec.size(), 2);
369 EXPECT_EQ(vec, result);
370 }
371
TEST(SmallVectorTest,Erase_range_5)372 TEST(SmallVectorTest, Erase_range_5) {
373 SmallVector<uint32_t, 6> vec = {0, 1, 2, 3};
374 SmallVector<uint32_t, 6> result = {0, 3};
375
376 EXPECT_EQ(vec.size(), 4);
377 vec.erase(vec.begin() + 1, vec.begin() + 3);
378 EXPECT_EQ(vec.size(), 2);
379 EXPECT_EQ(vec, result);
380 }
381
TEST(SmallVectorTest,Erase_range_6)382 TEST(SmallVectorTest, Erase_range_6) {
383 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
384 SmallVector<uint32_t, 2> result = {0, 3};
385
386 EXPECT_EQ(vec.size(), 4);
387 vec.erase(vec.begin() + 1, vec.begin() + 3);
388 EXPECT_EQ(vec.size(), 2);
389 EXPECT_EQ(vec, result);
390 }
391
TEST(SmallVectorTest,Push_back)392 TEST(SmallVectorTest, Push_back) {
393 SmallVector<uint32_t, 2> vec;
394 SmallVector<uint32_t, 2> result = {0, 1, 2, 3};
395
396 EXPECT_EQ(vec.size(), 0);
397 vec.push_back(0);
398 EXPECT_EQ(vec.size(), 1);
399 vec.push_back(1);
400 EXPECT_EQ(vec.size(), 2);
401 vec.push_back(2);
402 EXPECT_EQ(vec.size(), 3);
403 vec.push_back(3);
404 EXPECT_EQ(vec.size(), 4);
405 EXPECT_EQ(vec, result);
406 }
407
TEST(SmallVectorTest,Emplace_back)408 TEST(SmallVectorTest, Emplace_back) {
409 SmallVector<uint32_t, 2> vec;
410 SmallVector<uint32_t, 2> result = {0, 1, 2, 3};
411
412 EXPECT_EQ(vec.size(), 0);
413 vec.emplace_back(0);
414 EXPECT_EQ(vec.size(), 1);
415 vec.emplace_back(1);
416 EXPECT_EQ(vec.size(), 2);
417 vec.emplace_back(2);
418 EXPECT_EQ(vec.size(), 3);
419 vec.emplace_back(3);
420 EXPECT_EQ(vec.size(), 4);
421 EXPECT_EQ(vec, result);
422 }
423
TEST(SmallVectorTest,Clear)424 TEST(SmallVectorTest, Clear) {
425 SmallVector<uint32_t, 2> vec = {0, 1, 2, 3};
426 SmallVector<uint32_t, 2> result = {};
427
428 EXPECT_EQ(vec.size(), 4);
429 vec.clear();
430 EXPECT_EQ(vec.size(), 0);
431 EXPECT_EQ(vec, result);
432 }
433
TEST(SmallVectorTest,Insert1)434 TEST(SmallVectorTest, Insert1) {
435 SmallVector<uint32_t, 2> vec = {};
436 SmallVector<uint32_t, 2> insert_values = {10, 11};
437 SmallVector<uint32_t, 2> result = {10, 11};
438
439 EXPECT_EQ(vec.size(), 0);
440 auto ret =
441 vec.insert(vec.begin(), insert_values.begin(), insert_values.end());
442 EXPECT_EQ(vec.size(), 2);
443 EXPECT_EQ(vec, result);
444 EXPECT_EQ(*ret, 10);
445 }
446
TEST(SmallVectorTest,Insert2)447 TEST(SmallVectorTest, Insert2) {
448 SmallVector<uint32_t, 2> vec = {};
449 SmallVector<uint32_t, 2> insert_values = {10, 11, 12};
450 SmallVector<uint32_t, 2> result = {10, 11, 12};
451
452 EXPECT_EQ(vec.size(), 0);
453 auto ret =
454 vec.insert(vec.begin(), insert_values.begin(), insert_values.end());
455 EXPECT_EQ(vec.size(), 3);
456 EXPECT_EQ(vec, result);
457 EXPECT_EQ(*ret, 10);
458 }
459
TEST(SmallVectorTest,Insert3)460 TEST(SmallVectorTest, Insert3) {
461 SmallVector<uint32_t, 2> vec = {0};
462 SmallVector<uint32_t, 2> insert_values = {10, 11, 12};
463 SmallVector<uint32_t, 2> result = {10, 11, 12, 0};
464
465 EXPECT_EQ(vec.size(), 1);
466 auto ret =
467 vec.insert(vec.begin(), insert_values.begin(), insert_values.end());
468 EXPECT_EQ(vec.size(), 4);
469 EXPECT_EQ(vec, result);
470 EXPECT_EQ(*ret, 10);
471 }
472
TEST(SmallVectorTest,Insert4)473 TEST(SmallVectorTest, Insert4) {
474 SmallVector<uint32_t, 6> vec = {0};
475 SmallVector<uint32_t, 6> insert_values = {10, 11, 12};
476 SmallVector<uint32_t, 6> result = {10, 11, 12, 0};
477
478 EXPECT_EQ(vec.size(), 1);
479 auto ret =
480 vec.insert(vec.begin(), insert_values.begin(), insert_values.end());
481 EXPECT_EQ(vec.size(), 4);
482 EXPECT_EQ(vec, result);
483 EXPECT_EQ(*ret, 10);
484 }
485
TEST(SmallVectorTest,Insert5)486 TEST(SmallVectorTest, Insert5) {
487 SmallVector<uint32_t, 2> vec = {0, 1, 2};
488 SmallVector<uint32_t, 2> insert_values = {10, 11, 12};
489 SmallVector<uint32_t, 2> result = {0, 1, 2, 10, 11, 12};
490
491 EXPECT_EQ(vec.size(), 3);
492 auto ret = vec.insert(vec.end(), insert_values.begin(), insert_values.end());
493 EXPECT_EQ(vec.size(), 6);
494 EXPECT_EQ(vec, result);
495 EXPECT_EQ(*ret, 10);
496 }
497
TEST(SmallVectorTest,Insert6)498 TEST(SmallVectorTest, Insert6) {
499 SmallVector<uint32_t, 6> vec = {0, 1, 2};
500 SmallVector<uint32_t, 6> insert_values = {10, 11, 12};
501 SmallVector<uint32_t, 6> result = {0, 1, 2, 10, 11, 12};
502
503 EXPECT_EQ(vec.size(), 3);
504 auto ret = vec.insert(vec.end(), insert_values.begin(), insert_values.end());
505 EXPECT_EQ(vec.size(), 6);
506 EXPECT_EQ(vec, result);
507 EXPECT_EQ(*ret, 10);
508 }
509
TEST(SmallVectorTest,Insert7)510 TEST(SmallVectorTest, Insert7) {
511 SmallVector<uint32_t, 2> vec = {0, 1, 2};
512 SmallVector<uint32_t, 2> insert_values = {10, 11, 12};
513 SmallVector<uint32_t, 2> result = {0, 10, 11, 12, 1, 2};
514
515 EXPECT_EQ(vec.size(), 3);
516 auto ret =
517 vec.insert(vec.begin() + 1, insert_values.begin(), insert_values.end());
518 EXPECT_EQ(vec.size(), 6);
519 EXPECT_EQ(vec, result);
520 EXPECT_EQ(*ret, 10);
521 }
522
TEST(SmallVectorTest,Insert8)523 TEST(SmallVectorTest, Insert8) {
524 SmallVector<uint32_t, 6> vec = {0, 1, 2};
525 SmallVector<uint32_t, 6> insert_values = {10, 11, 12};
526 SmallVector<uint32_t, 6> result = {0, 10, 11, 12, 1, 2};
527
528 EXPECT_EQ(vec.size(), 3);
529 auto ret =
530 vec.insert(vec.begin() + 1, insert_values.begin(), insert_values.end());
531 EXPECT_EQ(vec.size(), 6);
532 EXPECT_EQ(vec, result);
533 EXPECT_EQ(*ret, 10);
534 }
535
TEST(SmallVectorTest,Resize1)536 TEST(SmallVectorTest, Resize1) {
537 SmallVector<uint32_t, 2> vec = {0, 1, 2};
538 SmallVector<uint32_t, 2> result = {0, 1, 2, 10, 10, 10};
539
540 EXPECT_EQ(vec.size(), 3);
541 vec.resize(6, 10);
542 EXPECT_EQ(vec.size(), 6);
543 EXPECT_EQ(vec, result);
544 }
545
TEST(SmallVectorTest,Resize2)546 TEST(SmallVectorTest, Resize2) {
547 SmallVector<uint32_t, 8> vec = {0, 1, 2};
548 SmallVector<uint32_t, 8> result = {0, 1, 2, 10, 10, 10};
549
550 EXPECT_EQ(vec.size(), 3);
551 vec.resize(6, 10);
552 EXPECT_EQ(vec.size(), 6);
553 EXPECT_EQ(vec, result);
554 }
555
TEST(SmallVectorTest,Resize3)556 TEST(SmallVectorTest, Resize3) {
557 SmallVector<uint32_t, 4> vec = {0, 1, 2};
558 SmallVector<uint32_t, 4> result = {0, 1, 2, 10, 10, 10};
559
560 EXPECT_EQ(vec.size(), 3);
561 vec.resize(6, 10);
562 EXPECT_EQ(vec.size(), 6);
563 EXPECT_EQ(vec, result);
564 }
565
TEST(SmallVectorTest,Resize4)566 TEST(SmallVectorTest, Resize4) {
567 SmallVector<uint32_t, 4> vec = {0, 1, 2, 10, 10, 10};
568 SmallVector<uint32_t, 4> result = {0, 1, 2};
569
570 EXPECT_EQ(vec.size(), 6);
571 vec.resize(3, 10);
572 EXPECT_EQ(vec.size(), 3);
573 EXPECT_EQ(vec, result);
574 }
575
TEST(SmallVectorTest,Resize5)576 TEST(SmallVectorTest, Resize5) {
577 SmallVector<uint32_t, 2> vec = {0, 1, 2, 10, 10, 10};
578 SmallVector<uint32_t, 2> result = {0, 1, 2};
579
580 EXPECT_EQ(vec.size(), 6);
581 vec.resize(3, 10);
582 EXPECT_EQ(vec.size(), 3);
583 EXPECT_EQ(vec, result);
584 }
585
TEST(SmallVectorTest,Resize6)586 TEST(SmallVectorTest, Resize6) {
587 SmallVector<uint32_t, 8> vec = {0, 1, 2, 10, 10, 10};
588 SmallVector<uint32_t, 8> result = {0, 1, 2};
589
590 EXPECT_EQ(vec.size(), 6);
591 vec.resize(3, 10);
592 EXPECT_EQ(vec.size(), 3);
593 EXPECT_EQ(vec, result);
594 }
595
596 } // namespace
597 } // namespace utils
598 } // namespace spvtools
599