First test good

This commit is contained in:
2026-03-21 23:05:37 -06:00
parent 52c7e3dfff
commit 7d9f751baf
2 changed files with 15 additions and 1 deletions

View File

@@ -231,7 +231,7 @@ LinkedListErr LinkedList<T>::set(size_t index, const T& val) {
template <LinkedListSupported T> template <LinkedListSupported T>
LinkedListErr LinkedList<T>::insert(size_t index, const T& value) { LinkedListErr LinkedList<T>::insert(size_t index, const T& value) {
if (this->is_empty()) { if (this->is_empty() && index == 0) {
return this->append(value); return this->append(value);
} }
@@ -425,5 +425,9 @@ size_t LinkedList<T>::len() {
return this->size; return this->size;
} }
template <LinkedListSupported T>
bool LinkedList<T>::is_empty() {
return this->len() < 1;
}
#endif // ! #endif // !

View File

@@ -247,3 +247,13 @@ TEST_CASE("Find 1 value not present", "[linkedlist]") {
auto result = list.find(80); auto result = list.find(80);
REQUIRE(result.error() == LinkedListErr::LINKEDLIST_NOT_FOUND); REQUIRE(result.error() == LinkedListErr::LINKEDLIST_NOT_FOUND);
} }
TEST_CASE("Insert at empty list", "[linkedlist]") {
LinkedList<int> list = {};
REQUIRE(list.len() == 0);
list.insert(0, 8);
REQUIRE(list.len() == 1);
REQUIRE(list.get(0) == 8);
}