diff --git a/test/DFSTest.cpp b/test/DFSTest.cpp index 795c75253..388b9ff2b 100644 --- a/test/DFSTest.cpp +++ b/test/DFSTest.cpp @@ -139,3 +139,61 @@ TEST(DFSTest, test_6) { 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_7) { + CXXGraph::Node node1("1", 1); + CXXGraph::Node node2("2", 2); + CXXGraph::Node node3("3", 3); + CXXGraph::Node node4("4", 4); + std::pair *, const CXXGraph::Node *> pairNode( + &node1, &node2); + CXXGraph::DirectedWeightedEdge edge1(1, pairNode, 1); + CXXGraph::DirectedWeightedEdge edge2(2, node2, node3, 1); + CXXGraph::DirectedWeightedEdge edge3(3, node3, node4, 1); + CXXGraph::DirectedWeightedEdge edge4(4, node4, node1, 1); + CXXGraph::T_EdgeSet edgeSet; + edgeSet.insert(make_shared>(edge1)); + edgeSet.insert(make_shared>(edge2)); + edgeSet.insert(make_shared>(edge3)); + edgeSet.insert(make_shared>(edge4)); + CXXGraph::Graph graph(edgeSet); + std::vector> res = graph.depth_first_search(node1); + ASSERT_EQ(res.size(), 4); + ASSERT_TRUE(std::find(res.begin(), res.end(), node1) != res.end()); + ASSERT_TRUE(std::find(res.begin(), res.end(), node2) != res.end()); + 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 node1("1", 1); + CXXGraph::Node node2("2", 2); + CXXGraph::Node node3("3", 3); + CXXGraph::Node node4("4", 4); + + CXXGraph::DirectedWeightedEdge edge1(1, node1, node2, 1); + CXXGraph::DirectedWeightedEdge edge2(2, node3, node4, 1); + CXXGraph::T_EdgeSet edgeSet; + edgeSet.insert(make_shared>(edge1)); + edgeSet.insert(make_shared>(edge2)); + CXXGraph::Graph graph(edgeSet); + std::vector> 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 node1("1", 1); + std::pair *, const CXXGraph::Node *> pairNode( + &node1, &node1); + CXXGraph::UndirectedWeightedEdge edge1(1, pairNode, 1); + CXXGraph::T_EdgeSet edgeSet; + edgeSet.insert(make_shared>(edge1)); + CXXGraph::Graph graph(edgeSet); + std::vector> res = graph.depth_first_search(node1); + ASSERT_EQ(res.size(), 1); + ASSERT_TRUE(std::find(res.begin(), res.end(), node1) != res.end()); +}