34 lines
811 B
C++
34 lines
811 B
C++
#include "iassert.h"
|
|
#include "vec.h"
|
|
|
|
int main() {
|
|
{
|
|
Vec *v = new Vec();
|
|
delete v;
|
|
}
|
|
|
|
Vec v;
|
|
v.push_back(10);
|
|
int a = v[0];
|
|
ASSERT_EQMSG(10, a, "10 should be present at index 0");
|
|
|
|
Vec v2{1, 2, 3};
|
|
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_EQ(12, v3.size());
|
|
ASSERT_EQ(24, v3.capacity());
|
|
|
|
Vec v_sized(40);
|
|
v_sized.push_back(0);
|
|
ASSERT_MSG(v_sized[0] == 0, "Well");
|
|
|
|
return 0;
|
|
}
|