Skip to content

Commit

Permalink
closer
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jun 18, 2024
1 parent ffbc2d7 commit 989da18
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 114 deletions.
219 changes: 111 additions & 108 deletions tests/common_tests/chowdsp_data_structures_test/AbstractTreeTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <CatchUtils.h>
#include <chowdsp_data_structures/chowdsp_data_structures.h>

#if ! JUCE_WINDOWS // @TODO

struct StringTree : chowdsp::AbstractTree<std::string, StringTree>
{
static Node& insert_string (std::string&& element, Node& parent_node, AbstractTree& tree)
Expand Down Expand Up @@ -48,114 +50,115 @@ TEST_CASE ("Abstract Tree Test", "[common][data-structures]")
tree.insertElement ("almonds");
REQUIRE (tree.size() == 5);

// {
// const auto* a_node = tree.getRootNode().first_child;
// REQUIRE (a_node->tag == "a");
// REQUIRE (a_node->first_child->leaf == "alfalfa");
// REQUIRE (a_node->first_child->next_sibling->leaf == "almonds");
// REQUIRE (a_node->first_child->next_sibling->next_sibling->leaf == "apples");
// }
//
// tree.insertElement ("acai");
// REQUIRE (tree.size() == 6);
//
// {
// const auto* a_node = tree.getRootNode().first_child;
// REQUIRE (a_node->tag == "a");
// REQUIRE (a_node->first_child->leaf == "acai");
// REQUIRE (a_node->first_child->next_sibling->leaf == "alfalfa");
// REQUIRE (a_node->first_child->next_sibling->next_sibling->leaf == "almonds");
// REQUIRE (a_node->first_child->next_sibling->next_sibling->next_sibling->leaf == "apples");
// }
{
const auto* a_node = tree.getRootNode().first_child;
REQUIRE (a_node->tag == "a");
REQUIRE (a_node->first_child->leaf == "alfalfa");
REQUIRE (a_node->first_child->next_sibling->leaf == "almonds");
REQUIRE (a_node->first_child->next_sibling->next_sibling->leaf == "apples");
}

tree.insertElement ("acai");
REQUIRE (tree.size() == 6);

{
const auto* a_node = tree.getRootNode().first_child;
REQUIRE (a_node->tag == "a");
REQUIRE (a_node->first_child->leaf == "acai");
REQUIRE (a_node->first_child->next_sibling->leaf == "alfalfa");
REQUIRE (a_node->first_child->next_sibling->next_sibling->leaf == "almonds");
REQUIRE (a_node->first_child->next_sibling->next_sibling->next_sibling->leaf == "apples");
}
}

SECTION ("Remove One")
{
tree.removeElement ("beets");
REQUIRE (tree.size() == 3);

const auto* d_node = tree.getRootNode().first_child->next_sibling;
REQUIRE (d_node->tag == "d");
}

SECTION ("Remove From Start of Sub-Tree")
{
tree.removeElement ("alfalfa");
REQUIRE (tree.size() == 3);

const auto* a_node = tree.getRootNode().first_child;
REQUIRE (a_node->first_child->leaf == "apples");
}

SECTION ("Remove From End of Sub-Tree")
{
tree.removeElement ("apples");
REQUIRE (tree.size() == 3);

const auto* a_node = tree.getRootNode().first_child;
REQUIRE (a_node->last_child->leaf == "alfalfa");
}

SECTION ("Remove Last Node in Sub-Tree")
{
tree.removeElement ("donuts");
REQUIRE (tree.size() == 3);

const auto* b_node = tree.getRootNode().last_child;
REQUIRE (b_node->tag == "b");
}

SECTION ("Remove Multiple")
{
tree.removeElements ([] (const std::string& el)
{ return el.find ('t') != std::string::npos; });
REQUIRE (tree.size() == 2);

REQUIRE (tree.getRootNode().first_child == tree.getRootNode().last_child);
REQUIRE (tree.getRootNode().first_child->tag == "a");
}

// SECTION ("Remove One")
// {
// tree.removeElement ("beets");
// REQUIRE (tree.size() == 3);
//
// const auto* d_node = tree.getRootNode().first_child->next_sibling;
// REQUIRE (d_node->tag == "d");
// }
//
// SECTION ("Remove From Start of Sub-Tree")
// {
// tree.removeElement ("alfalfa");
// REQUIRE (tree.size() == 3);
//
// const auto* a_node = tree.getRootNode().first_child;
// REQUIRE (a_node->first_child->leaf == "apples");
// }
//
// SECTION ("Remove From End of Sub-Tree")
// {
// tree.removeElement ("apples");
// REQUIRE (tree.size() == 3);
//
// const auto* a_node = tree.getRootNode().first_child;
// REQUIRE (a_node->last_child->leaf == "alfalfa");
// }
//
// SECTION ("Remove Last Node in Sub-Tree")
// {
// tree.removeElement ("donuts");
// REQUIRE (tree.size() == 3);
//
// const auto* b_node = tree.getRootNode().last_child;
// REQUIRE (b_node->tag == "b");
// }

// SECTION ("Remove Multiple")
// {
// tree.removeElements ([] (const std::string& el)
// { return el.find ('t') != std::string::npos; });
// REQUIRE (tree.size() == 2);
//
// REQUIRE (tree.getRootNode().first_child == tree.getRootNode().last_child);
// REQUIRE (tree.getRootNode().first_child->tag == "a");
// }
//
// SECTION ("Remove All")
// {
// tree.removeElements ([] (const std::string& el)
// { return ! el.empty(); });
// REQUIRE (tree.size() == 0);
//
// tree.insertElement ("mussels");
// REQUIRE (tree.size() == 1);
// REQUIRE (tree.getRootNode().first_child->tag == "m");
// REQUIRE (tree.getRootNode().first_child->first_child->leaf == "mussels");
//
// auto* found = tree.findElement ("mussels");
// REQUIRE (found != nullptr);
// }
//
// SECTION ("Find Success")
// {
// auto* found = std::as_const (tree).findElement ("apples");
// jassert (found != nullptr);
// }
//
// SECTION ("Find Fail")
// {
// [[maybe_unused]] auto* found = std::as_const (tree).findElement ("bologna");
// jassert (found == nullptr);
// }
//
// SECTION ("To Uppercase")
// {
// tree.doForAllElements (
// [] (std::string& str)
// {
// for (auto& c : str)
// c = static_cast<char> (std::toupper (static_cast<int> (c)));
// });
//
// std::as_const (tree).doForAllElements (
// [] (const std::string& str)
// {
// for (auto& c : str)
// REQUIRE (((c >= 'A') && (c <= 'Z')));
// });
// }
SECTION ("Remove All")
{
tree.removeElements ([] (const std::string& el)
{ return ! el.empty(); });
REQUIRE (tree.size() == 0);

tree.insertElement ("mussels");
REQUIRE (tree.size() == 1);
REQUIRE (tree.getRootNode().first_child->tag == "m");
REQUIRE (tree.getRootNode().first_child->first_child->leaf == "mussels");

auto* found = tree.findElement ("mussels");
REQUIRE (found != nullptr);
}

SECTION ("Find Success")
{
auto* found = std::as_const (tree).findElement ("apples");
jassert (found != nullptr);
}

SECTION ("Find Fail")
{
[[maybe_unused]] auto* found = std::as_const (tree).findElement ("bologna");
jassert (found == nullptr);
}

SECTION ("To Uppercase")
{
tree.doForAllElements (
[] (std::string& str)
{
for (auto& c : str)
c = static_cast<char> (std::toupper (static_cast<int> (c)));
});

std::as_const (tree).doForAllElements (
[] (const std::string& str)
{
for (auto& c : str)
REQUIRE (((c >= 'A') && (c <= 'Z')));
});
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ TEST_CASE ("Enum Map Test", "[common][data-structures]")
iter = 0;
for (auto [key, val] : map)
val = static_cast<int> (iter++);
// REQUIRE (map[Food::Apple] == 0);
// REQUIRE (map[Food::Green_Beans] == 1);
REQUIRE (map[Food::Apple] == 0);
REQUIRE (map[Food::Green_Beans] == 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ TEST_CASE ("STL Arena Allocator Test", "[common][data-structures]")
REQUIRE (vec.front() == 1);
REQUIRE (vec.back() == 4);

// vec.push_back (5);
// REQUIRE (vec.size() == 5);
// REQUIRE (vec.back() == 5);
//
vec.push_back (5);
REQUIRE (vec.size() == 5);
REQUIRE (vec.back() == 5);

// vec.erase (vec.begin());
// REQUIRE (vec.size() == 4);
// vec.insert (vec.begin(), 0);
Expand Down

0 comments on commit 989da18

Please sign in to comment.