MRPT  2.0.4
vector_with_small_size_optimization_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <CTraitsTest.h>
11 #include <gtest/gtest.h>
13 #include <mrpt/core/common.h>
14 
15 using data_t = unsigned int;
16 constexpr size_t SMALL_LEN = 16;
17 
18 using vwsso_t =
20 
21 template class mrpt::CTraitsTest<vwsso_t>;
22 
23 TEST(vector_with_small_size_optimization, Empty)
24 {
25  vwsso_t v;
26 
27  EXPECT_TRUE(v.empty());
28  EXPECT_TRUE(v.size() == 0);
29 }
30 
31 TEST(vector_with_small_size_optimization, ResizeSize)
32 {
33  // New one each time:
34  for (size_t n = 1; n < SMALL_LEN * 2; n++)
35  {
36  vwsso_t v;
37  v.resize(n);
38  EXPECT_FALSE(v.empty());
39  EXPECT_EQ(v.size(), n);
40  }
41 
42  // Reusing object:
43  vwsso_t v;
44  for (size_t n = 1; n < SMALL_LEN * 2; n++)
45  {
46  v.resize(n);
47  EXPECT_FALSE(v.empty());
48  EXPECT_EQ(v.size(), n);
49  }
50 }
51 
52 TEST(vector_with_small_size_optimization, ResizeWriteRead)
53 {
54  // New one each time:
55  for (size_t n = 1; n < SMALL_LEN * 2; n++)
56  {
57  vwsso_t v;
58  v.resize(n);
59 
60  for (size_t i = 0; i < n; i++) v[i] = i;
61  for (size_t i = 0; i < n; i++) EXPECT_EQ(v[i], i);
62  }
63 
64  // Reusing object:
65  vwsso_t v;
66  for (size_t n = 1; n < SMALL_LEN * 2; n++)
67  {
68  v.resize(n);
69  for (size_t i = 0; i < n; i++) v[i] = i;
70  for (size_t i = 0; i < n; i++) EXPECT_EQ(v[i], i);
71  }
72 }
73 
74 TEST(vector_with_small_size_optimization, ResizeWriteReadIterators)
75 {
76  // New one each time:
77  for (size_t n = 1; n < SMALL_LEN * 2; n++)
78  {
79  vwsso_t v;
80  v.resize(n);
81 
82  for (size_t i = 0; i < n; i++) v[i] = i;
83 
84  size_t i = 0;
85  for (const auto& val : v)
86  {
87  EXPECT_EQ(val, i);
88  i++;
89  }
90  }
91 
92  // Reusing object:
93  vwsso_t v;
94  for (size_t n = 1; n < SMALL_LEN * 2; n++)
95  {
96  v.resize(n);
97  for (size_t i = 0; i < n; i++) v[i] = i;
98  size_t i = 0;
99  for (const auto& val : v)
100  {
101  EXPECT_EQ(val, i);
102  i++;
103  }
104  }
105 }
106 
107 TEST(vector_with_small_size_optimization, GrowCheckContents)
108 {
109  vwsso_t v;
110  for (size_t n = 1; n < SMALL_LEN * 2; n++)
111  {
112  v.resize(n);
113  v[n - 1] = n - 1;
114 
115  for (size_t i = 0; i < n; i++) EXPECT_EQ(v[i], i) << "n=" << n;
116  }
117 }
118 
119 TEST(vector_with_small_size_optimization, ShrinkCheckContents)
120 {
121  vwsso_t v;
122  v.resize(SMALL_LEN * 2);
123  for (size_t i = 0; i < v.size(); i++) v[i] = i;
124 
125  while (!v.empty())
126  {
127  v.resize(v.size() - 1);
128 
129  for (size_t i = 0; i < v.size(); i++)
130  EXPECT_EQ(v[i], i) << "size()=" << v.size();
131  }
132 }
133 
134 TEST(vector_with_small_size_optimization, GrowCheckFrontBack)
135 {
136  vwsso_t v;
137  for (size_t n = 1; n < SMALL_LEN * 2; n++)
138  {
139  v.resize(n);
140  EXPECT_EQ(&v[0], &v.front()) << "n=" << n;
141  EXPECT_EQ(&v[n - 1], &v.back()) << "n=" << n;
142  }
143 }
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
Container that transparently and dynamically switches between a std::array and std::vector.
int val
Definition: mrpt_jpeglib.h:957
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
TEST(vector_with_small_size_optimization, Empty)



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020