mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:57:44 +00:00
AK: Use Vector::empend() a bit in the unit tests, and fix a bug.
There was a bug in the "prepend_vector_object" test but it was masked by us not printing failures. (The bug was that we were adding three elements to the "objects" vector and then checking that another vector called "more_objects" indeed had three elements. Oops!)
This commit is contained in:
parent
8434548f14
commit
9230b42f28
1 changed files with 23 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
#include <AK/TestSuite.h>
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/TestSuite.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
TEST_CASE(construct)
|
||||
|
@ -102,36 +102,43 @@ TEST_CASE(prepend_vector)
|
|||
TEST_CASE(prepend_vector_object)
|
||||
{
|
||||
struct SubObject {
|
||||
SubObject(int v) : value(v) {}
|
||||
SubObject(int v)
|
||||
: value(v)
|
||||
{
|
||||
}
|
||||
int value { 0 };
|
||||
};
|
||||
struct Object {
|
||||
OwnPtr<SubObject> object;
|
||||
Object(NonnullOwnPtr<SubObject>&& a_subobject)
|
||||
: subobject(move(a_subobject))
|
||||
{
|
||||
}
|
||||
OwnPtr<SubObject> subobject;
|
||||
};
|
||||
|
||||
Vector<Object> objects;
|
||||
objects.append({ make<SubObject>(1) });
|
||||
objects.append({ make<SubObject>(2) });
|
||||
objects.append({ make<SubObject>(3) });
|
||||
objects.empend(make<SubObject>(1));
|
||||
objects.empend(make<SubObject>(2));
|
||||
objects.empend(make<SubObject>(3));
|
||||
|
||||
EXPECT_EQ(objects.size(), 3);
|
||||
|
||||
Vector<Object> more_objects;
|
||||
objects.append({ make<SubObject>(4) });
|
||||
objects.append({ make<SubObject>(5) });
|
||||
objects.append({ make<SubObject>(6) });
|
||||
EXPECT_EQ(more_objects.size(), 3);
|
||||
more_objects.empend(make<SubObject>(4));
|
||||
more_objects.empend(make<SubObject>(5));
|
||||
more_objects.empend(make<SubObject>(6));
|
||||
EXPECT_EQ(more_objects.size(), 4);
|
||||
|
||||
objects.prepend(move(more_objects));
|
||||
EXPECT_EQ(more_objects.size(), 0);
|
||||
EXPECT_EQ(objects.size(), 6);
|
||||
|
||||
EXPECT_EQ(objects[0].object->value, 4);
|
||||
EXPECT_EQ(objects[1].object->value, 5);
|
||||
EXPECT_EQ(objects[2].object->value, 6);
|
||||
EXPECT_EQ(objects[3].object->value, 1);
|
||||
EXPECT_EQ(objects[4].object->value, 2);
|
||||
EXPECT_EQ(objects[5].object->value, 3);
|
||||
EXPECT_EQ(objects[0].subobject->value, 4);
|
||||
EXPECT_EQ(objects[1].subobject->value, 5);
|
||||
EXPECT_EQ(objects[2].subobject->value, 6);
|
||||
EXPECT_EQ(objects[3].subobject->value, 1);
|
||||
EXPECT_EQ(objects[4].subobject->value, 2);
|
||||
EXPECT_EQ(objects[5].subobject->value, 3);
|
||||
}
|
||||
|
||||
TEST_MAIN(Vector)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue