Skip to content

Commit 7c73723

Browse files
committed
Implement erase tests
1 parent 27405bd commit 7c73723

File tree

1 file changed

+99
-2
lines changed

1 file changed

+99
-2
lines changed

tests/beman/inplace_vector/spec.test2.experimental.cpp

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,50 @@ TYPED_TEST(Modifiers, EraseSingle) {
13681368
<< "device still have " << device.size() << " elements";
13691369
}
13701370

1371+
TYPED_TEST(Modifiers, EraseSingleConst) {
1372+
// constexpr iterator erase(const_iterator position);
1373+
// constexpr iterator erase(const_iterator first, const_iterator last);
1374+
// constexpr void pop_back();
1375+
//
1376+
// Effects: Invalidates iterators and references at or after the point of the
1377+
// erase.
1378+
// Throws: Nothing unless an exception is thrown by the assignment
1379+
// operator or move assignment operator of T.
1380+
// Complexity: The destructor of T is called the number of times equal to the
1381+
// number of the elements erased, but the assignment operator of T is called
1382+
// the number of times equal to the number of elements after the erased
1383+
// elements.
1384+
1385+
auto device = this->unique();
1386+
1387+
if (device.empty())
1388+
return;
1389+
1390+
auto itr = device.erase(device.cbegin());
1391+
if (device.empty())
1392+
return;
1393+
1394+
EXPECT_EQ(itr, device.cbegin());
1395+
1396+
auto last_itr = device.cend();
1397+
last_itr = --last_itr;
1398+
1399+
itr = device.erase(last_itr);
1400+
EXPECT_EQ(itr, device.cend());
1401+
1402+
auto mid_idx = device.size() / 2;
1403+
auto mid_itr = device.cbegin() + mid_idx;
1404+
itr = device.erase(mid_itr);
1405+
EXPECT_EQ(itr, device.cbegin() + mid_idx);
1406+
1407+
auto size = device.size();
1408+
for (auto i = 0; i < size; ++i)
1409+
device.erase(device.cbegin());
1410+
1411+
EXPECT_TRUE(device.empty())
1412+
<< "device still have " << device.size() << " elements";
1413+
}
1414+
13711415
TYPED_TEST(Modifiers, EraseRange) {
13721416
// constexpr iterator erase(const_iterator first, const_iterator last);
13731417
//
@@ -1380,8 +1424,61 @@ TYPED_TEST(Modifiers, EraseRange) {
13801424
// the number of times equal to the number of elements after the erased
13811425
// elements.
13821426

1383-
// TODO
1384-
GTEST_SKIP();
1427+
using IV = TestFixture::IV;
1428+
1429+
auto reference = this->unique();
1430+
IV device(reference);
1431+
1432+
auto itr = device.erase(device.begin(), device.begin());
1433+
EXPECT_EQ(itr, device.begin());
1434+
EXPECT_EQ(device, IV(reference));
1435+
1436+
if (device.empty())
1437+
return;
1438+
1439+
itr = device.erase(device.begin(), device.begin() + 1);
1440+
EXPECT_EQ(itr, device.begin());
1441+
EXPECT_EQ(device, IV(reference.begin() + 1, reference.end()));
1442+
1443+
if (device.empty())
1444+
return;
1445+
1446+
reference = IV(device);
1447+
1448+
auto last_itr = device.end() - 1;
1449+
1450+
itr = device.erase(last_itr, device.end());
1451+
EXPECT_EQ(itr, device.end());
1452+
EXPECT_EQ(device, IV(reference.begin(), reference.end() - 1));
1453+
1454+
if (device.size() >= 4) {
1455+
reference = IV(device);
1456+
1457+
auto from_itr = device.begin() + 1;
1458+
auto to_itr = device.end() - 1;
1459+
1460+
itr = device.erase(from_itr, to_itr);
1461+
EXPECT_EQ(itr, device.begin() + 1);
1462+
EXPECT_EQ(device, IV({reference[0], reference.back()}));
1463+
}
1464+
}
1465+
1466+
TYPED_TEST(Modifiers, EraseRangeAll) {
1467+
// constexpr iterator erase(const_iterator first, const_iterator last);
1468+
//
1469+
// Effects: Invalidates iterators and references at or after the point of the
1470+
// erase.
1471+
// Throws: Nothing unless an exception is thrown by the assignment
1472+
// operator or move assignment operator of T.
1473+
// Complexity: The destructor of T is called the number of times equal to the
1474+
// number of the elements erased, but the assignment operator of T is called
1475+
// the number of times equal to the number of elements after the erased
1476+
// elements.
1477+
1478+
auto device = this->unique();
1479+
auto itr = device.erase(device.begin(), device.end());
1480+
EXPECT_EQ(itr, device.end());
1481+
EXPECT_TRUE(device.empty());
13851482
}
13861483

13871484
TYPED_TEST(Modifiers, PopBack) {

0 commit comments

Comments
 (0)