Skip to content

Commit

Permalink
added visualization tests for all tree classes
Browse files Browse the repository at this point in the history
  • Loading branch information
spirosmaggioros committed Sep 25, 2024
1 parent e804853 commit 4929346
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 3 deletions.
21 changes: 21 additions & 0 deletions tests/tree/avl.cc
Original file line number Diff line number Diff line change
@@ -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 <string>
Expand Down Expand Up @@ -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<int> 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<char> a({'g', 'w', 'h', 'p', 'u'});
CHECK_NOTHROW(a.visualize());
}

#endif
28 changes: 28 additions & 0 deletions tests/tree/bst.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "../../src/visualization/tree_visual/tree_visualization.h"
#include "../../src/classes/tree/bst.h"
#include "../../third_party/catch.hpp"
#include <string>
Expand Down Expand Up @@ -149,3 +150,30 @@ TEST_CASE("testing level order in bst"){
std::vector<std::vector<int>> 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<int> 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<char> b;
b.insert('g');
b.insert('a');
b.insert('b');
b.insert('w');
CHECK_NOTHROW(b.visualize());
}

#endif
23 changes: 23 additions & 0 deletions tests/tree/interval_tree.cc
Original file line number Diff line number Diff line change
@@ -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 <string>
Expand Down Expand Up @@ -79,3 +80,25 @@ TEST_CASE("testing level order in interval tree"){
std::vector<std::vector<std::pair<int,int>>> 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<int> 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<char> i({{'a', 'b'}, {'c', 'd'}, {'a', 'd'}});
CHECK_NOTHROW(i.visualize());
}



#endif
13 changes: 10 additions & 3 deletions tests/tree/red_black_tree.cc
Original file line number Diff line number Diff line change
@@ -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 <algorithm>
Expand Down Expand Up @@ -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<int> rb({10,15,25,9,8,13,45});
CHECK_NOTHROW(rb.visualize());

red_black_tree<char> t({'a', 'c', 'e', 'g', 'd', 'f', 'u'});
CHECK_NOTHROW(t.visualize());
}




#endif
24 changes: 24 additions & 0 deletions tests/tree/splay_tree.cc
Original file line number Diff line number Diff line change
@@ -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 <string>
Expand Down Expand Up @@ -126,3 +127,26 @@ TEST_CASE("testing level order for splay tree"){
std::vector<std::vector<int>> 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<int> 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<char> s({'a', 'w', 'g', 'o', 's', 'v'});
CHECK_NOTHROW(s.visualize());
}

#endif
27 changes: 27 additions & 0 deletions tests/tree/tree.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "../../src/visualization/tree_visual/tree_visualization.h"
#include "../../third_party/catch.hpp"
#include "../../src/classes/tree/tree.h"
#include <string>
Expand Down Expand Up @@ -51,3 +52,29 @@ TEST_CASE("testing level order traversal in tree class [TREECLASS]"){
std::vector<std::vector<int>> 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<int> 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<char> tt;
tt.insert("", 'c');
tt.insert("l", 'w');
tt.insert("r", 'd');
CHECK_NOTHROW(tt.visualize());
}

#endif

0 comments on commit 4929346

Please sign in to comment.