Skip to content

Commit

Permalink
added a new DFStest (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikDervishi03 authored Dec 13, 2023
1 parent f4bb68a commit b876335
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions test/DFSTest.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <memory>

#include "CXXGraph/CXXGraph.hpp"
#include "gtest/gtest.h"

// Smart pointers alias
template <typename T>
using unique = std::unique_ptr<T>;
template <typename T>
using shared= std::shared_ptr<T>;
using shared = std::shared_ptr<T>;

using std::make_unique;
using std::make_shared;
using std::make_unique;

TEST(DFSTest, test_1) {
CXXGraph::Node<int> node1("1", 1);
Expand Down Expand Up @@ -138,3 +139,28 @@ 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<int> node1("1", 1);
CXXGraph::Node<int> node2("2", 2);
CXXGraph::Node<int> node3("3", 3);
CXXGraph::Node<int> node4("4", 4);
std::pair<const CXXGraph::Node<int> *, const CXXGraph::Node<int> *> pairNode(
&node1, &node2);
CXXGraph::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGraph::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGraph::DirectedWeightedEdge<int> edge3(3, node3, node4, 1);
CXXGraph::DirectedWeightedEdge<int> edge4(4, node4, node1, 1);
CXXGraph::T_EdgeSet<int> edgeSet;
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge1));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge2));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge3));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge4));
CXXGraph::Graph<int> graph(edgeSet);
std::vector<CXXGraph::Node<int>> 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());
}

0 comments on commit b876335

Please sign in to comment.