diff --git a/src/extra/containers/bubble.h b/src/extra/containers/bubble.h index 3fb52d3f..d618a63f 100644 --- a/src/extra/containers/bubble.h +++ b/src/extra/containers/bubble.h @@ -40,10 +40,10 @@ class bubble { } template - void insert(Args&& ...keys); + void insert(Args ...keys); template - void remove(Args&& ...keys); + void remove(Args ...keys); bool search(const T& key); @@ -83,7 +83,7 @@ class bubble { template template -inline void bubble::insert(Args&& ...keys) { +inline void bubble::insert(Args ...keys) { auto _insert = [&](const T&& key) -> void { if(_size < _SIZE) { list.push_back({key, std::nullopt}); @@ -138,8 +138,8 @@ inline void bubble::insert(Args&& ...keys) { */ template template -void bubble::remove(Args&& ...keys) { - auto _remove = [&](const T& key) -> void{ +void bubble::remove(Args ...keys) { + auto _remove = [&](const T&& key) -> void{ if(this->_size == 0) { return; } if(this->_size <= _SIZE) { auto [begin, end] = std::ranges::remove_if(this->list, [&](const std::pair>> &t) { return t.first == key; }); diff --git a/src/extra/tests/bubble.cc b/src/extra/tests/bubble.cc index 6accf627..9bbd1d68 100644 --- a/src/extra/tests/bubble.cc +++ b/src/extra/tests/bubble.cc @@ -1,5 +1,7 @@ +#define CATCH_CONFIG_MAIN #include "../../../third_party/catch.hpp" #include "../containers/bubble.h" +#include #include TEST_CASE("Testing insertion for bubble class") { @@ -13,6 +15,27 @@ TEST_CASE("Testing insertion for bubble class") { REQUIRE(b[4][0] == 50); } +TEST_CASE("Testing searching for bubble class") { + bubble b; + + b.insert("a", "c", "i", "l", "y"); + b.insert("because", "bee", "before"); + b.insert("careful", "coconut", "circle"); + b.insert("ker"); + b.insert("normal", "normalize"); + b.insert("wow"); + REQUIRE(b.search("wow") == true); + REQUIRE(b.search("coconut") == true); + REQUIRE(b.search("a") == true); + REQUIRE(b.search("before") == true); + b.remove("wow"); + REQUIRE(b.search("wow") == false); + b.remove("before"); + REQUIRE(b.search("before") == false); + b.remove("c"); + REQUIRE(b.search("c") == false); +} + TEST_CASE("Testing removing for bubble class") { bubble b; b.insert('a', 'd', 'h', 'k', 'w');