Skip to content

Commit

Permalink
More test cases for graph class
Browse files Browse the repository at this point in the history
### Repl
Still, both graph classes have a problem with visualization when the first element is std::string, this needs a fix asap.
  • Loading branch information
spirosmaggioros committed Aug 3, 2024
1 parent 7285cbc commit 79821e3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
41 changes: 39 additions & 2 deletions tests/graph/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST_CASE("testing dfs in graph") {
REQUIRE(v == dfs);
}

TEST_CASE("testing bfs in graph") {
TEST_CASE("testing dfs in graph [2]") {
graph<int> g("directed");
g.add_edge(1, 4);
g.add_edge(4, 5);
Expand Down Expand Up @@ -242,7 +242,7 @@ TEST_CASE("Testing operator << for graph class") {
CHECK_NOTHROW(std::cout << g2 << '\n');
}

TEST_CASE("Testing bfs function for graph class") {
TEST_CASE("Testing dfs function for graph class [3]") {
graph<int> g("directed");
g.add_edge(0, 1);
g.add_edge(1, 2);
Expand All @@ -252,3 +252,40 @@ TEST_CASE("Testing bfs function for graph class") {
std::vector<int> path = {0, 1, 2, 3, 4};
REQUIRE(dfs_path == path);
}

TEST_CASE("Testing bfs function for graph class [1]") {
graph<int> g("directed");
g.add_edge(0, 1);
g.add_edge(1, 2);
g.add_edge(2, 3);
g.add_edge(3, 4);
std::vector<int> bfs_path = g.bfs(0);
std::vector<int> path = {0, 1, 2, 3, 4};
REQUIRE(bfs_path == path);
}

TEST_CASE("Testing operator = for graph class") {
graph<int> g("directed");
g.add_edge(0, 1);
g.add_edge(1, 2);
g.add_edge(2, 3);
g.add_edge(3, 4);

graph<int> g2 = g;
std::vector<int> dfs_path = g.dfs(0);
std::vector<int> dfs_path_2 = g2.dfs(0);
REQUIRE(dfs_path == dfs_path_2);
}


TEST_CASE("Testing clear function for graph class") {
graph<int> g("directed");
g.add_edge(0, 1);
g.add_edge(1, 2);
g.add_edge(2, 3);
g.add_edge(3, 4);

g.clear();
std::vector<int> bfs_path = g.bfs(0);
REQUIRE(bfs_path.size() == 0);
}
33 changes: 31 additions & 2 deletions tests/graph/weighted_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ TEST_CASE("Testing visualization for weighted graph class") {
g.add_edge(1, 2, 5);
g.add_edge(2, 4, 5);
g.add_edge(4, 1, 10);
g.visualize();
CHECK_NOTHROW(g.visualize());
}

TEST_CASE("Testing bfs for weighted graph class") {
TEST_CASE("Testing dfs for weighted graph class") {
weighted_graph<int> g("undirected");
g.add_edge(1, 2, 5);
g.add_edge(2, 4, 5);
Expand All @@ -265,3 +265,32 @@ TEST_CASE("Testing bfs for weighted graph class") {
REQUIRE(dfs_path.size() != 0);
REQUIRE(dfs_path[0] == 1);
}

TEST_CASE("Testing visualization with std::string for weighted graph class") {
weighted_graph<char> g2("directed");
g2.add_edge('a', 'b', 10);
g2.add_edge('b', 'c', 10);
g2.add_edge('c', 'd', 25);
CHECK_NOTHROW(g2.visualize());
}

TEST_CASE("Testing bfs function for weighted graph class") {
weighted_graph<int> g("directed");
g.add_edge(0, 1, 10);
g.add_edge(1, 2, 5);
g.add_edge(2, 3, 6);
g.add_edge(3, 4, 11);
std::vector<int> bfs_path = g.bfs(0);
std::vector<int> path = {0, 1, 2, 3, 4};
REQUIRE(bfs_path == path);
}

TEST_CASE("Testing clear function for weighted graph class") {
weighted_graph<int> g("directed");
g.add_edge(0, 1, 10);
g.add_edge(1, 2, 5);
g.add_edge(2, 3, 6);
g.add_edge(3, 4, 11);
std::vector<int> bfs_path = g.bfs(0);
REQUIRE(bfs_path.size() == 0);
}

0 comments on commit 79821e3

Please sign in to comment.