Skip to content

Commit

Permalink
added comments and more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
spirosmaggioros committed Feb 4, 2024
1 parent 41be804 commit 1f97e34
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/classes/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,35 @@ template <typename T> class graph {
}
}

~graph() { adj.clear(); }

graph(const graph& g) {
/**
* @brief Construct a new graph object
*
* @param g the graph we want to copy
*/
graph(const graph &g) {
adj = g.adj;
__elements = g.__elements;
__type = g.__type;
}
graph& operator=(const graph& g) {

/**
* @brief operator = for the graph class
*
* @param g the graph we want to copy
* @return graph&
*/
graph &operator=(const graph &g) {
adj = g.adj;
__elements = g.__elements;
__type = g.__type;
return *this;
}

/**
* @brief Destroy the graph object
*/
~graph() { adj.clear(); }

/**
* @brief add_edge function
* @param u: first node
Expand Down
13 changes: 12 additions & 1 deletion tests/graph/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,16 @@ TEST_CASE("testing copy constructor") {
graph<int> g2 = g;
REQUIRE(g.dfs(1) == g1.dfs(1));
REQUIRE(g.dfs(1) == g2.dfs(1));
}

graph<char> g3("directed");
g3.add_edge('a', 'b');
g3.add_edge('b', 'd');
g3.add_edge('c', 'd');
g3.add_edge('w', 'd');
g3.add_edge('d', 'a');

graph<char> g4 = g3;
graph<char> g5(g3);
REQUIRE(g4.dfs('a') == g3.dfs('a'));
REQUIRE(g5.dfs('a') == g3.dfs('a'));
}

0 comments on commit 1f97e34

Please sign in to comment.