MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / basicTests

Method basicTests

Tests/Libraries/Containers/VectorTest.cpp:173–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173void SC::VectorTest::basicTests()
174{
175 if (test_section("remove"))
176 {
177 Vector<String> strings;
178 SC_TEST_EXPECT(strings.append({"0", "1", "2", "3", "4", "5"}));
179 SC_TEST_EXPECT(strings[1] == "1");
180 SC_TEST_EXPECT(strings.removeAt(1));
181 SC_TEST_EXPECT(strings[1] == "2");
182 SC_TEST_EXPECT(strings.removeAt(3));
183 }
184 if (test_section("insert"))
185 {
186 Vector<String> strings;
187 // insert empty
188 SC_TEST_EXPECT(strings.insert(0, {"3"}));
189 SC_TEST_EXPECT(strings[0] == "3");
190 // insert front
191 SC_TEST_EXPECT(strings.insert(0, {"0"}));
192 SC_TEST_EXPECT(strings[0] == "0");
193 SC_TEST_EXPECT(strings[1] == "3");
194 SC_TEST_EXPECT(strings.reserve(3));
195 SC_TEST_EXPECT(strings[0] == "0");
196 SC_TEST_EXPECT(strings[1] == "3");
197 // insert end
198 SC_TEST_EXPECT(strings.insert(2, {"5"}));
199 SC_TEST_EXPECT(strings[0] == "0");
200 SC_TEST_EXPECT(strings[1] == "3");
201 SC_TEST_EXPECT(strings[2] == "5");
202 // insert one before end (no moved in elements)
203 SC_TEST_EXPECT(strings.insert(2, {"4"}));
204 SC_TEST_EXPECT(strings[0] == "0");
205 SC_TEST_EXPECT(strings[1] == "3");
206 SC_TEST_EXPECT(strings[2] == "4");
207 SC_TEST_EXPECT(strings[3] == "5");
208 // insert 3 before end (1 move assigned + 2 move constructed elements)
209 SC_TEST_EXPECT(strings.insert(1, {"1", "2"}));
210 SC_TEST_EXPECT(strings[0] == "0");
211 SC_TEST_EXPECT(strings[1] == "1");
212 SC_TEST_EXPECT(strings[2] == "2");
213 SC_TEST_EXPECT(strings[3] == "3");
214 SC_TEST_EXPECT(strings[4] == "4");
215 SC_TEST_EXPECT(strings[5] == "5");
216 SC_TEST_EXPECT(strings.size() == 6);
217 // sanity check to allow inserting zero size with no effect
218 SC_TEST_EXPECT(strings.insert(0, {}));
219 SC_TEST_EXPECT(strings.size() == 6);
220 SC_TEST_EXPECT(strings[0] == "0");
221 SC_TEST_EXPECT(strings[1] == "1");
222 SC_TEST_EXPECT(strings[2] == "2");
223 SC_TEST_EXPECT(strings[3] == "3");
224 SC_TEST_EXPECT(strings[4] == "4");
225 SC_TEST_EXPECT(strings[5] == "5");
226 // insert error outside range (after last element)
227 SC_TEST_EXPECT(not strings.insert(7, {"6"}));
228 {
229 // Special insert case that will test some edge cases
230 strings = {};

Callers

nothing calls this directly

Calls 10

reserveMethod · 0.80
pop_backMethod · 0.80
appendMethod · 0.45
insertMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
clearMethod · 0.45
isEmptyMethod · 0.45
capacityMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected