From 018bbb0b2a44f94192e08b4859aa4fd23b20af36 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 7 Jul 2021 16:07:33 +0200 Subject: [PATCH] Test: PityTest - add test_pitytree.cc --- test/pitytest11/test/test_pitytree.cc | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/pitytest11/test/test_pitytree.cc diff --git a/test/pitytest11/test/test_pitytree.cc b/test/pitytest11/test/test_pitytree.cc new file mode 100644 index 0000000..d0b03dc --- /dev/null +++ b/test/pitytest11/test/test_pitytree.cc @@ -0,0 +1,62 @@ +#include "../src/PityTree.hh" +#include "../src/PityTest.hh" +//#include "../../../src/utils.hh" +#include +#include +using namespace pEp::PityTest11; + +class Node : public PityTree { +public: + Node() = delete; + Node(const std::string &name); + Node(const std::string &name, Node &parent); + + std::string color; + int age; +}; + +Node::Node(const std::string &name) : PityTree(*this, name) {} + +Node::Node(const std::string &name, Node &parent) : PityTree(*this, name, parent) {} + +std::string readKey() +{ + std::string ret; + std::cin >> ret; + return ret; +} + +void not_throwing(){ + throw std::runtime_error{"Fsd"}; +} + +void throwing(){ + throw std::runtime_error{"Fsd"}; +} + +int main(int argc, char *argv[]) +{ + Node a{ "a" }; + std::cout << a.getPath() << std::endl; + PITYASSERT(a.isRoot() == true, ""); + PITYASSERT(a.getName() == "a",""); + PITYASSERT(&(a.getRoot()) == &a,""); + PITYASSERT(a.getParent() == nullptr,""); + PITYASSERT(a.getChildren().size() == 0,""); + + Node b{ "b", a }; + std::cout << b.getPath() << std::endl; + PITYASSERT(a.isRoot() == true,""); + PITYASSERT(&(a.getRoot()) == &a,""); + PITYASSERT(a.getParent() == nullptr,""); + PITYASSERT(a.getChildren().size() == 1,""); + PITYASSERT(&b == &(a.getChild("b")),""); + PITYASSERT_THROWS(a.getChild("invalid"),""); + + PITYASSERT(b.isRoot() == false,""); + PITYASSERT(&(b.getRoot()) == &a,""); + PITYASSERT(b.getParent() == &a,""); + PITYASSERT(b.getChildren().size() == 0,""); + + std::cout << a.to_string() << std::endl; +}