#include "Tree/tree.hpp" #include "catch2/catch_test_macros.hpp" #include "catch2/matchers/catch_matchers.hpp" #include #define CATCH_CONFIG_MAIN #include SCENARIO("Testing Base Tree Methods") { GIVEN("Nothing") { WHEN("Root Node is created") { std::shared_ptr root = nullptr; REQUIRE_NOTHROW(root = std::make_shared()); THEN("attributed are as expected") { REQUIRE_FALSE(root == nullptr); REQUIRE(root->getRoot() == root); REQUIRE(root->getParent() == nullptr); REQUIRE(root->getNrChildren() == 0); REQUIRE(root->getNrDirectChildren() == 0); REQUIRE(root->getChildrenBegin() == root->getChildrenEnd()); REQUIRE(root->type() == "Tree::TreeRoot"); REQUIRE(root->base() == "Tree::Base"); } } } AND_GIVEN("A valid Root Node") { auto root = std::make_shared(); WHEN("adding a temporary node") { auto temp = std::make_shared(); root->addChild(temp); THEN("the tree is correct") { REQUIRE_FALSE(root == nullptr); REQUIRE(root->getRoot() == root); REQUIRE(root->getParent() == nullptr); REQUIRE(root->getNrChildren() == 1); REQUIRE(root->getNrDirectChildren() == 1); REQUIRE(root->type() == "Tree::TreeRoot"); REQUIRE(root->base() == "Tree::Base"); std::shared_ptr child; REQUIRE_NOTHROW(child = std::static_pointer_cast(*(root->getChildrenBegin()))); REQUIRE(child->getRoot() == root); REQUIRE(child->getParent() == root); REQUIRE(child->getNrChildren() == 0); REQUIRE(child->getNrDirectChildren() == 0); REQUIRE(child->type() == "Tree::TempNode"); REQUIRE(child->base() == "Tree::Base"); } } } }