Merge "Fix linked_list::remove_if()"
am: 004fead6bc * commit '004fead6bc55d1e65b4fb9ca1ac36646b99e5fdd': Fix linked_list::remove_if()
This commit is contained in:
commit
2dc1e91dba
@ -127,6 +127,11 @@ class LinkedList {
|
|||||||
} else {
|
} else {
|
||||||
p->next = next;
|
p->next = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tail_ == e) {
|
||||||
|
tail_ = p;
|
||||||
|
}
|
||||||
|
|
||||||
Allocator::free(e);
|
Allocator::free(e);
|
||||||
e = next;
|
e = next;
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,6 +133,23 @@ TEST(linked_list, remove_if_then_pop) {
|
|||||||
ASSERT_TRUE(list.pop_front() == nullptr);
|
ASSERT_TRUE(list.pop_front() == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(linked_list, remove_if_last_then_push_back) {
|
||||||
|
test_list_t list;
|
||||||
|
|
||||||
|
list.push_back("a");
|
||||||
|
list.push_back("b");
|
||||||
|
list.push_back("c");
|
||||||
|
list.push_back("d");
|
||||||
|
|
||||||
|
list.remove_if([](const char* c) {
|
||||||
|
return *c == 'c' || *c == 'd';
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_EQ("ab", test_list_to_string(list));
|
||||||
|
list.push_back("d");
|
||||||
|
ASSERT_EQ("abd", test_list_to_string(list));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(linked_list, copy_to_array) {
|
TEST(linked_list, copy_to_array) {
|
||||||
test_list_t list;
|
test_list_t list;
|
||||||
const size_t max_size = 128;
|
const size_t max_size = 128;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user