From aee8f1328914fa3d6aa618e99f83ba10c06e6883 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Tue, 11 Jun 2019 22:07:40 -0400 Subject: [PATCH] List fix remove() and update testing --- src/include/containers/BlockingList.hpp | 2 +- src/include/containers/List.hpp | 8 +++++++- src/systemcmds/tests/test_List.cpp | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/include/containers/BlockingList.hpp b/src/include/containers/BlockingList.hpp index 27e3f896cf..0a68f783f3 100644 --- a/src/include/containers/BlockingList.hpp +++ b/src/include/containers/BlockingList.hpp @@ -68,7 +68,7 @@ public: return List::remove(removeNode); } - size_t size() const + size_t size() { LockGuard lg{_mutex}; return List::size(); diff --git a/src/include/containers/List.hpp b/src/include/containers/List.hpp index c005cf17a4..5cf7447beb 100644 --- a/src/include/containers/List.hpp +++ b/src/include/containers/List.hpp @@ -70,7 +70,13 @@ public: { // base case if (removeNode == _head) { - _head = nullptr; + if (_head->getSibling() != nullptr) { + _head = _head->getSibling(); + + } else { + _head = nullptr; + } + return true; } diff --git a/src/systemcmds/tests/test_List.cpp b/src/systemcmds/tests/test_List.cpp index 5baabde5d9..14936410d6 100644 --- a/src/systemcmds/tests/test_List.cpp +++ b/src/systemcmds/tests/test_List.cpp @@ -141,6 +141,8 @@ bool ListTest::test_remove() for (auto t : list1) { ut_assert_true(t->i != remove_i); } + + ut_assert_true(list1.size() == 100 - remove_i - 1); } // list should now be empty