Better tests

This commit is contained in:
Imbus 2025-01-11 17:33:21 +01:00
parent 91bf5ecec0
commit 7226b7aea6

View file

@ -9,21 +9,26 @@ int main() {
Vec v;
v.push_back(10);
ASSERT_MSG(v[0] == 10, "10 should be present at index 0");
int a = v[0];
ASSERT_EQMSG(10, a, "10 should be present at index 0");
Vec v2{1, 2, 3};
ASSERT_MSG(v2.size() == 3, "Size should be three");
ASSERT_EQ(3, v2.size());
ASSERT_EQMSG(v2.size(), 3, "Size should be three");
v2.pop_back();
ASSERT_EQ(2, v2.size());
ASSERT_MSG(v2.size() == 2, "Size should be three");
// Triggers a reallocation (memcpy)
Vec v3{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
ASSERT_MSG(v3[11] == 12, "Index 11 should hold 12");
// ASSERT_MSG(v3[5] == 6, "Index 5 should hold 6"); // ???
ASSERT_MSG(v3.size() == 12, "Size should be 12");
ASSERT_MSG(v3.capacity() == 20, "Capacity should be 20");
ASSERT_MSG(v3[5] == 6, "Index 5 should hold 6"); // ???
ASSERT_EQ(12, v3.size());
ASSERT_EQ(24, v3.capacity());
for (const auto &a : v3) {
std::cout << a << std::endl;
}
Vec v_sized(40);
v_sized.push_back(0);
ASSERT_MSG(v_sized[0] == 0, "Well");
return 0;
}