Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests and examples #376

Merged
merged 8 commits into from
Dec 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added a test_8 and test_9 in DFSTest
  • Loading branch information
ErikDervishi03 committed Dec 13, 2023
commit 6a939dead74c7515c3504a905becd03f3f184c64
33 changes: 33 additions & 0 deletions test/DFSTest.cpp
Original file line number Diff line number Diff line change
@@ -164,3 +164,36 @@ TEST(DFSTest, test_7) {
ASSERT_TRUE(std::find(res.begin(), res.end(), node3) != res.end());
ASSERT_TRUE(std::find(res.begin(), res.end(), node4) != res.end());
}

TEST(DFSTest, test_8) {
CXXGraph::Node<int> node1("1", 1);
CXXGraph::Node<int> node2("2", 2);
CXXGraph::Node<int> node3("3", 3);
CXXGraph::Node<int> node4("4", 4);

CXXGraph::DirectedWeightedEdge<int> edge1(1, node1, node2, 1);
CXXGraph::DirectedWeightedEdge<int> edge2(2, node3, node4, 1);
CXXGraph::T_EdgeSet<int> edgeSet;
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge1));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge2));
CXXGraph::Graph<int> graph(edgeSet);
std::vector<CXXGraph::Node<int>> res = graph.depth_first_search(node1);
ASSERT_EQ(res.size(), 2);
ASSERT_TRUE(std::find(res.begin(), res.end(), node1) != res.end());
ASSERT_TRUE(std::find(res.begin(), res.end(), node2) != res.end());
ASSERT_FALSE(std::find(res.begin(), res.end(), node3) != res.end());
ASSERT_FALSE(std::find(res.begin(), res.end(), node4) != res.end());
}

TEST(DFSTest, test_9) {
CXXGraph::Node<int> node1("1", 1);
std::pair<const CXXGraph::Node<int> *, const CXXGraph::Node<int> *> pairNode(
&node1, &node1);
CXXGraph::UndirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGraph::T_EdgeSet<int> edgeSet;
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge1));
CXXGraph::Graph<int> graph(edgeSet);
std::vector<CXXGraph::Node<int>> res = graph.depth_first_search(node1);
ASSERT_EQ(res.size(), 1);
ASSERT_TRUE(std::find(res.begin(), res.end(), node1) != res.end());
}