From 49293464a7eb88ae3c79727ad3fd0f85bc3183b9 Mon Sep 17 00:00:00 2001 From: Spiros Maggioros Date: Wed, 25 Sep 2024 14:06:04 +0300 Subject: [PATCH] added visualization tests for all tree classes --- tests/tree/avl.cc | 21 +++++++++++++++++++++ tests/tree/bst.cc | 28 ++++++++++++++++++++++++++++ tests/tree/interval_tree.cc | 23 +++++++++++++++++++++++ tests/tree/red_black_tree.cc | 13 ++++++++++--- tests/tree/splay_tree.cc | 24 ++++++++++++++++++++++++ tests/tree/tree.cc | 27 +++++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 3 deletions(-) diff --git a/tests/tree/avl.cc b/tests/tree/avl.cc index 42a3b80a..1752d9fa 100644 --- a/tests/tree/avl.cc +++ b/tests/tree/avl.cc @@ -1,3 +1,4 @@ +#include "../../src/visualization/tree_visual/tree_visualization.h" #include "../../src/classes/tree/avl_tree.h" #include "../../third_party/catch.hpp" #include @@ -162,3 +163,23 @@ TEST_CASE("Testing get_root function in avl tree"){ t.remove(35); REQUIRE(t.get_root() == 36); } + +#define TREE_VISUALIZATION_H +#ifdef TREE_VISUALIZATION_H + +TEST_CASE("Testing avl tree visualization") { + avl_tree t; + t.insert(35); + t.insert(30); + t.insert(38); + t.insert(22); + t.insert(36); + t.insert(45); + + CHECK_NOTHROW(t.visualize()); + + avl_tree a({'g', 'w', 'h', 'p', 'u'}); + CHECK_NOTHROW(a.visualize()); +} + +#endif diff --git a/tests/tree/bst.cc b/tests/tree/bst.cc index 80d41a78..9a260aa2 100644 --- a/tests/tree/bst.cc +++ b/tests/tree/bst.cc @@ -1,3 +1,4 @@ +#include "../../src/visualization/tree_visual/tree_visualization.h" #include "../../src/classes/tree/bst.h" #include "../../third_party/catch.hpp" #include @@ -149,3 +150,30 @@ TEST_CASE("testing level order in bst"){ std::vector> sol = {{5}, {1,6}, {2,8}, {3,7,10}, {4,9}}; REQUIRE(produced == sol); } + +#define TREE_VISUALIZATION_H +#ifdef TREE_VISUALIZATION_H + +TEST_CASE("Testing binary search tree visualization") { + bst t; + t.insert(5); + t.insert(1); + t.insert(2); + t.insert(3); + t.insert(6); + t.insert(8); + t.insert(7); + t.insert(10); + t.insert(9); + t.insert(4); + CHECK_NOTHROW(t.visualize()); + + bst b; + b.insert('g'); + b.insert('a'); + b.insert('b'); + b.insert('w'); + CHECK_NOTHROW(b.visualize()); +} + +#endif diff --git a/tests/tree/interval_tree.cc b/tests/tree/interval_tree.cc index a1696044..16524f45 100644 --- a/tests/tree/interval_tree.cc +++ b/tests/tree/interval_tree.cc @@ -1,3 +1,4 @@ +#include "../../src/visualization/tree_visual/tree_visualization.h" #include "../../src/classes/tree/interval_tree.h" #include "../../third_party/catch.hpp" #include @@ -79,3 +80,25 @@ TEST_CASE("testing level order in interval tree"){ std::vector>> sol = {{{15,20}}, {{8,13}, {19,30}}, {{1,20}, {12,15}, {17,19}, {22,25}}}; REQUIRE(produced==sol); } + +#define TREE_VISUALIZATION_H +#ifdef TREE_VISUALIZATION_H + +TEST_CASE("Testing interval tree visualization") { + interval_tree t; + t.insert({15,20}); + t.insert({8,13}); + t.insert({1,20}); + t.insert({12,15}); + t.insert({19,30}); + t.insert({17,19}); + t.insert({22,25}); + CHECK_NOTHROW(t.visualize()); + + interval_tree i({{'a', 'b'}, {'c', 'd'}, {'a', 'd'}}); + CHECK_NOTHROW(i.visualize()); +} + + + +#endif diff --git a/tests/tree/red_black_tree.cc b/tests/tree/red_black_tree.cc index 7e699881..507d2657 100644 --- a/tests/tree/red_black_tree.cc +++ b/tests/tree/red_black_tree.cc @@ -1,3 +1,4 @@ +#include "../../src/visualization/tree_visual/tree_visualization.h" #include "../../src/classes/tree/red_black_tree.h" #include "../../third_party/catch.hpp" #include @@ -162,9 +163,15 @@ TEST_CASE("Testing level order in red black tree [2]") { REQUIRE(produced == expected); } +#define TREE_VISUALIZATION_H +#ifdef TREE_VISUALIZATION_H +TEST_CASE("Testing red black tree visualization") { + red_black_tree rb({10,15,25,9,8,13,45}); + CHECK_NOTHROW(rb.visualize()); + red_black_tree t({'a', 'c', 'e', 'g', 'd', 'f', 'u'}); + CHECK_NOTHROW(t.visualize()); +} - - - +#endif diff --git a/tests/tree/splay_tree.cc b/tests/tree/splay_tree.cc index 8dbc7742..04e2926e 100644 --- a/tests/tree/splay_tree.cc +++ b/tests/tree/splay_tree.cc @@ -1,3 +1,4 @@ +#include "../../src/visualization/tree_visual/tree_visualization.h" #include "../../src/classes/tree/splay_tree.h" #include "../../third_party/catch.hpp" #include @@ -126,3 +127,26 @@ TEST_CASE("testing level order for splay tree"){ std::vector> sol = {{4}, {3,8}, {2,6,9}, {1,5,7,10}}; REQUIRE(produced==sol); } + +#define TREE_VISUALIZATION_H +#ifdef TREE_VISUALIZATION_H + +TEST_CASE("Testing splay tree visualization") { + splay_tree t; + t.insert(5); + t.insert(1); + t.insert(2); + t.insert(3); + t.insert(6); + t.insert(8); + t.insert(7); + t.insert(10); + t.insert(9); + t.insert(4); + CHECK_NOTHROW(t.visualize()); + + splay_tree s({'a', 'w', 'g', 'o', 's', 'v'}); + CHECK_NOTHROW(s.visualize()); +} + +#endif diff --git a/tests/tree/tree.cc b/tests/tree/tree.cc index d32ba15f..d0de6f33 100644 --- a/tests/tree/tree.cc +++ b/tests/tree/tree.cc @@ -1,3 +1,4 @@ +#include "../../src/visualization/tree_visual/tree_visualization.h" #include "../../third_party/catch.hpp" #include "../../src/classes/tree/tree.h" #include @@ -51,3 +52,29 @@ TEST_CASE("testing level order traversal in tree class [TREECLASS]"){ std::vector> sol = {{1},{2,3},{4,5,6,7},{8,9,10}}; REQUIRE(produced == sol); } + +#define TREE_VISUALIZATION_H +#ifdef TREE_VISUALIZATION_H + +TEST_CASE("Testing tree visualization") { + tree t; + t.insert("", 1); + t.insert("l", 2); + t.insert("r", 3); + t.insert("ll", 4); + t.insert("lr", 5); + t.insert("rl", 6); + t.insert("rr", 7); + t.insert("lll", 8); + t.insert("llr", 9); + t.insert("lrl", 10); + CHECK_NOTHROW(t.visualize()); + + tree tt; + tt.insert("", 'c'); + tt.insert("l", 'w'); + tt.insert("r", 'd'); + CHECK_NOTHROW(tt.visualize()); +} + +#endif