Skip to content

Commit

Permalink
Changed argument passing on bubble and some more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
spirosmaggioros committed Aug 18, 2024
1 parent 9dad2fc commit b48cf98
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/extra/containers/bubble.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class bubble {
}

template <typename... Args>
void insert(Args&& ...keys);
void insert(Args ...keys);

template <typename... Args>
void remove(Args&& ...keys);
void remove(Args ...keys);

bool search(const T& key);

Expand Down Expand Up @@ -83,7 +83,7 @@ class bubble {

template <typename T, size_t _SIZE>
template <typename... Args>
inline void bubble<T, _SIZE>::insert(Args&& ...keys) {
inline void bubble<T, _SIZE>::insert(Args ...keys) {
auto _insert = [&](const T&& key) -> void {
if(_size < _SIZE) {
list.push_back({key, std::nullopt});
Expand Down Expand Up @@ -138,8 +138,8 @@ inline void bubble<T, _SIZE>::insert(Args&& ...keys) {
*/
template <typename T, size_t _SIZE>
template <typename... Args>
void bubble<T, _SIZE>::remove(Args&& ...keys) {
auto _remove = [&](const T& key) -> void{
void bubble<T, _SIZE>::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, std::optional<avl_tree<T>>> &t) { return t.first == key; });
Expand Down
23 changes: 23 additions & 0 deletions src/extra/tests/bubble.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#define CATCH_CONFIG_MAIN
#include "../../../third_party/catch.hpp"
#include "../containers/bubble.h"
#include <string>
#include <cmath>

TEST_CASE("Testing insertion for bubble class") {
Expand All @@ -13,6 +15,27 @@ TEST_CASE("Testing insertion for bubble class") {
REQUIRE(b[4][0] == 50);
}

TEST_CASE("Testing searching for bubble class") {
bubble<std::string, 5> 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<char, 5> b;
b.insert('a', 'd', 'h', 'k', 'w');
Expand Down

0 comments on commit b48cf98

Please sign in to comment.