diff --git a/include/Graph.hpp b/include/Graph.hpp index 95638fb9c..f2f5efe81 100644 --- a/include/Graph.hpp +++ b/include/Graph.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -464,7 +465,7 @@ namespace CXXGRAPH class Graph { private: - std::set *> edgeSet; + std::list *> edgeSet; void addElementToAdjMatrix(AdjacencyMatrix &adjMatrix, const Node *nodeFrom, const Node *nodeTo, const Edge *edge) const; int writeToStandardFile_csv(const std::string &workingDir, const std::string &OFileName, bool compress, bool writeNodeFeat, bool writeEdgeWeight) const; @@ -478,13 +479,13 @@ namespace CXXGRAPH } InputOutputFormat; Graph() = default; - Graph(const std::set *> &edgeSet); + Graph(const std::list *> &edgeSet); ~Graph() = default; - const std::set *> &getEdgeSet() const; - void setEdgeSet(std::set *> &edgeSet); + const std::list *> &getEdgeSet() const; + void setEdgeSet(std::list *> &edgeSet); void addEdge(const Edge &edge); void removeEdge(unsigned long edgeId); - const std::set *> getNodeSet() const; + const std::list *> getNodeSet() const; const std::optional *> getEdge(unsigned long edgeId) const; /*This function generate a list of adjacency matrix with every element of the matrix * contain the node where is directed the link and the Edge corrispondent to the link @@ -568,27 +569,43 @@ namespace CXXGRAPH }; template - Graph::Graph(const std::set *> &edgeSet) + Graph::Graph(const std::list *> &edgeSet) { - this->edgeSet = edgeSet; + for (auto edgeSetIt = edgeSet.begin(); edgeSetIt != edgeSet.end(); ++edgeSetIt) + { + if (std::find(this->edgeSet.begin(), this->edgeSet.end(), *edgeSetIt) == this->edgeSet.end()) + { + this->edgeSet.push_back(*edgeSetIt); + } + } } template - const std::set *> &Graph::getEdgeSet() const + const std::list *> &Graph::getEdgeSet() const { return edgeSet; } template - void Graph::setEdgeSet(std::set *> &edgeSet) + void Graph::setEdgeSet(std::list *> &edgeSet) { - this->edgeSet = edgeSet; + this->edgeSet.clear(); + for (auto edgeSetIt = edgeSet.begin(); edgeSetIt != edgeSet.end(); ++edgeSetIt) + { + if (std::find(this->edgeSet.begin(), this->edgeSet.end(), *edgeSetIt) == this->edgeSet.end()) + { + this->edgeSet.push_back(*edgeSetIt); + } + } } template void Graph::addEdge(const Edge &edge) { - edgeSet.insert(&edge); + if (std::find(edgeSet.begin(), edgeSet.end(), &edge) == edgeSet.end()) + { + edgeSet.push_back(&edge); + } } template @@ -602,13 +619,19 @@ namespace CXXGRAPH } template - const std::set *> Graph::getNodeSet() const + const std::list *> Graph::getNodeSet() const { - std::set *> nodeSet; + std::list *> nodeSet; for (auto edge : edgeSet) { - nodeSet.insert(edge->getNodePair().first); - nodeSet.insert(edge->getNodePair().second); + if (std::find(nodeSet.begin(), nodeSet.end(), edge->getNodePair().first) == nodeSet.end()) + { + nodeSet.push_back(edge->getNodePair().first); + } + if (std::find(nodeSet.begin(), nodeSet.end(), edge->getNodePair().second) == nodeSet.end()) + { + nodeSet.push_back(edge->getNodePair().second); + } } return nodeSet; } @@ -712,13 +735,13 @@ namespace CXXGRAPH result.errorMessage = ""; result.result = INF_DOUBLE; auto nodeSet = getNodeSet(); - if (nodeSet.find(&source) == nodeSet.end()) + if (std::find(nodeSet.begin(), nodeSet.end(), &source) == nodeSet.end()) { // check if source node exist in the graph result.errorMessage = ERR_DIJ_SOURCE_NODE_NOT_IN_GRAPH; return result; } - if (nodeSet.find(&target) == nodeSet.end()) + if (std::find(nodeSet.begin(), nodeSet.end(), &target) == nodeSet.end()) { // check if target node exist in the graph result.errorMessage = ERR_DIJ_TARGET_NODE_NOT_IN_GRAPH; @@ -821,7 +844,7 @@ namespace CXXGRAPH std::vector> visited; auto nodeSet = getNodeSet(); //check is exist node in the graph - if (nodeSet.find(&start) == nodeSet.end()) + if (std::find(nodeSet.begin(), nodeSet.end(), &start) == nodeSet.end()) { return visited; } @@ -861,7 +884,7 @@ namespace CXXGRAPH std::vector> visited; auto nodeSet = getNodeSet(); //check is exist node in the graph - if (nodeSet.find(&start) == nodeSet.end()) + if (std::find(nodeSet.begin(), nodeSet.end(), &start) == nodeSet.end()) { return visited; } diff --git a/test/BFSTest.cpp b/test/BFSTest.cpp index 8eb380fe0..e7afbdd0d 100644 --- a/test/BFSTest.cpp +++ b/test/BFSTest.cpp @@ -10,10 +10,10 @@ TEST(BFSTest, test_1) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.breadth_first_search(node1); ASSERT_EQ(res.size(), 3); @@ -31,10 +31,10 @@ TEST(BFSTest, test_2) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.breadth_first_search(node2); ASSERT_EQ(res.size(), 2); @@ -52,10 +52,10 @@ TEST(BFSTest, test_3) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.breadth_first_search(node2); ASSERT_EQ(res.size(), 3); @@ -73,10 +73,10 @@ TEST(BFSTest, test_4) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.breadth_first_search(node3); ASSERT_EQ(res.size(), 3); @@ -94,10 +94,10 @@ TEST(BFSTest, test_5) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.breadth_first_search(node3); ASSERT_EQ(res.size(), 1); @@ -116,10 +116,10 @@ TEST(BFSTest, test_6) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.breadth_first_search(node4); ASSERT_EQ(res.size(), 0); diff --git a/test/CycleCheckTest.cpp b/test/CycleCheckTest.cpp index b7610256b..692c4e7d9 100644 --- a/test/CycleCheckTest.cpp +++ b/test/CycleCheckTest.cpp @@ -10,10 +10,10 @@ TEST(CycleCheckTest, test_1) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); bool res = graph.isCyclicDirectedGraphDFS(); ASSERT_EQ(res, false); @@ -27,9 +27,9 @@ TEST(CycleCheckTest, test_2) std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); CXXGRAPH::Graph graph(edgeSet); bool res = graph.isCyclicDirectedGraphDFS(); ASSERT_EQ(res, false); @@ -44,10 +44,10 @@ TEST(CycleCheckTest, test_3) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); bool res = graph.isCyclicDirectedGraphDFS(); ASSERT_EQ(res, false); @@ -62,10 +62,10 @@ TEST(CycleCheckTest, test_4) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node3, node1, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); bool res = graph.isCyclicDirectedGraphDFS(); ASSERT_EQ(res, true); @@ -80,10 +80,10 @@ TEST(CycleCheckTest, test_5) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); bool res = graph.isCyclicDirectedGraphBFS(); ASSERT_EQ(res, false); @@ -97,9 +97,9 @@ TEST(CycleCheckTest, test_6) std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); CXXGRAPH::Graph graph(edgeSet); bool res = graph.isCyclicDirectedGraphBFS(); ASSERT_EQ(res, false); @@ -114,10 +114,10 @@ TEST(CycleCheckTest, test_7) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); bool res = graph.isCyclicDirectedGraphBFS(); ASSERT_EQ(res, false); @@ -132,10 +132,10 @@ TEST(CycleCheckTest, test_8) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node3, node1, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); bool res = graph.isCyclicDirectedGraphBFS(); ASSERT_EQ(res, true); diff --git a/test/DFSTest.cpp b/test/DFSTest.cpp index ad754830b..b9c8f9099 100644 --- a/test/DFSTest.cpp +++ b/test/DFSTest.cpp @@ -10,10 +10,10 @@ TEST(DFSTest, test_1) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.depth_first_search(node1); ASSERT_EQ(res.size(), 3); @@ -31,10 +31,10 @@ TEST(DFSTest, test_2) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.depth_first_search(node2); ASSERT_EQ(res.size(), 2); @@ -52,10 +52,10 @@ TEST(DFSTest, test_3) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.depth_first_search(node2); ASSERT_EQ(res.size(), 3); @@ -73,10 +73,10 @@ TEST(DFSTest, test_4) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.depth_first_search(node3); ASSERT_EQ(res.size(), 3); @@ -94,10 +94,10 @@ TEST(DFSTest, test_5) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.depth_first_search(node3); ASSERT_EQ(res.size(), 1); @@ -116,10 +116,10 @@ TEST(DFSTest, test_6) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::DirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::vector> res = graph.depth_first_search(node4); ASSERT_EQ(res.size(), 0); diff --git a/test/DijkstraTest.cpp b/test/DijkstraTest.cpp index b31bf85bf..a4d64c794 100644 --- a/test/DijkstraTest.cpp +++ b/test/DijkstraTest.cpp @@ -10,10 +10,10 @@ TEST(DijkstraTest, test_1) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); CXXGRAPH::DijkstraResult res = graph.dijkstra(node1, node3); ASSERT_TRUE(res.success); @@ -30,10 +30,10 @@ TEST(DijkstraTest, test_2) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 5); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 4); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); CXXGRAPH::DijkstraResult res = graph.dijkstra(node1, node3); ASSERT_TRUE(res.success); @@ -50,10 +50,10 @@ TEST(DijkstraTest, test_3) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 5); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); CXXGRAPH::DijkstraResult res = graph.dijkstra(node1, node3); ASSERT_FALSE(res.success); @@ -68,9 +68,9 @@ TEST(DijkstraTest, test_4) CXXGRAPH::Node node3(3, 3); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); CXXGRAPH::DijkstraResult res = graph.dijkstra(node1, node2); ASSERT_FALSE(res.success); @@ -86,9 +86,9 @@ TEST(DijkstraTest, test_5) CXXGRAPH::Node node4(4, 4); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); CXXGRAPH::DijkstraResult res = graph.dijkstra(node4, node2); ASSERT_FALSE(res.success); @@ -104,9 +104,9 @@ TEST(DijkstraTest, test_6) CXXGRAPH::Node node4(4, 4); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); CXXGRAPH::DijkstraResult res = graph.dijkstra(node1, node4); ASSERT_FALSE(res.success); diff --git a/test/GraphTest.cpp b/test/GraphTest.cpp index 2f17e56f4..817009ba4 100644 --- a/test/GraphTest.cpp +++ b/test/GraphTest.cpp @@ -7,8 +7,8 @@ TEST(GraphTest, Constructor_1) CXXGRAPH::Node node2(2, 2); std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::Edge edge(1, pairNode); - std::set *> edgeSet; - edgeSet.insert(&edge); + std::list *> edgeSet; + edgeSet.push_back(&edge); CXXGRAPH::Graph graph(edgeSet); ASSERT_EQ(graph.getEdgeSet(), edgeSet); } @@ -19,8 +19,8 @@ TEST(GraphTest, GetEdge_1) CXXGRAPH::Node node2(2, 2); std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::Edge edge(1, pairNode); - std::set *> edgeSet; - edgeSet.insert(&edge); + std::list *> edgeSet; + edgeSet.push_back(&edge); CXXGRAPH::Graph graph(edgeSet); ASSERT_FALSE(graph.getEdge(2).has_value()); } @@ -31,8 +31,8 @@ TEST(GraphTest, GetEdge_2) CXXGRAPH::Node node2(2, 2); std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::Edge edge(1, pairNode); - std::set *> edgeSet; - edgeSet.insert(&edge); + std::list *> edgeSet; + edgeSet.push_back(&edge); CXXGRAPH::Graph graph(edgeSet); ASSERT_TRUE(graph.getEdge(1).has_value()); } @@ -43,8 +43,8 @@ TEST(GraphTest, GetEdge_3) CXXGRAPH::Node node2(2, 2); std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::Edge edge(1, pairNode); - std::set *> edgeSet; - edgeSet.insert(&edge); + std::list *> edgeSet; + edgeSet.push_back(&edge); CXXGRAPH::Graph graph(edgeSet); ASSERT_EQ(*(graph.getEdge(1).value()), edge); } @@ -55,13 +55,13 @@ TEST(GraphTest, GetNodeSet_1) CXXGRAPH::Node node2(2, 2); std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::Edge edge(1, pairNode); - std::set *> edgeSet; - edgeSet.insert(&edge); + std::list *> edgeSet; + edgeSet.push_back(&edge); CXXGRAPH::Graph graph(edgeSet); auto nodeSet = graph.getNodeSet(); ASSERT_EQ(nodeSet.size(), 2); - ASSERT_TRUE(nodeSet.find(&node1) != nodeSet.end()); - ASSERT_TRUE(nodeSet.find(&node2) != nodeSet.end()); + ASSERT_TRUE(std::find(nodeSet.begin(), nodeSet.end(),&node1) != nodeSet.end()); + ASSERT_TRUE(std::find(nodeSet.begin(), nodeSet.end(),&node2) != nodeSet.end()); } TEST(GraphTest, GetNodeSet_2) @@ -72,15 +72,15 @@ TEST(GraphTest, GetNodeSet_2) std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::Edge edge(1, pairNode); CXXGRAPH::UndirectedEdge edge2(2, node2, node3); - std::set *> edgeSet; - edgeSet.insert(&edge); - edgeSet.insert(&edge2); + std::list *> edgeSet; + edgeSet.push_back(&edge); + edgeSet.push_back(&edge2); CXXGRAPH::Graph graph(edgeSet); auto nodeSet = graph.getNodeSet(); ASSERT_EQ(nodeSet.size(), 3); - ASSERT_TRUE(nodeSet.find(&node1) != nodeSet.end()); - ASSERT_TRUE(nodeSet.find(&node2) != nodeSet.end()); - ASSERT_TRUE(nodeSet.find(&node3) != nodeSet.end()); + ASSERT_TRUE(std::find(nodeSet.begin(), nodeSet.end(),&node1) != nodeSet.end()); + ASSERT_TRUE(std::find(nodeSet.begin(), nodeSet.end(),&node2) != nodeSet.end()); + ASSERT_TRUE(std::find(nodeSet.begin(), nodeSet.end(),&node3) != nodeSet.end()); } TEST(GraphTest, adj_print_1) @@ -89,8 +89,8 @@ TEST(GraphTest, adj_print_1) CXXGRAPH::Node node2(2, 2); std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::Edge edge(1, pairNode); - std::set *> edgeSet; - edgeSet.insert(&edge); + std::list *> edgeSet; + edgeSet.push_back(&edge); CXXGRAPH::Graph graph(edgeSet); std::cout << "Test Print Adjacency Matrix" << std::endl; std::cout << graph.getAdjMatrix() << std::endl; @@ -102,8 +102,8 @@ TEST(GraphTest, adj_print_2) CXXGRAPH::Node node2(2, 2); std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::DirectedEdge edge(1, pairNode); - std::set *> edgeSet; - edgeSet.insert(&edge); + std::list *> edgeSet; + edgeSet.push_back(&edge); CXXGRAPH::Graph graph(edgeSet); std::cout << "Test Print Adjacency Matrix" << std::endl; std::cout << graph.getAdjMatrix() << std::endl; @@ -115,8 +115,8 @@ TEST(GraphTest, adj_print_3) CXXGRAPH::Node node2(2, 2); std::pair *, const CXXGRAPH::Node *> pairNode(&node1, &node2); CXXGRAPH::UndirectedEdge edge(1, pairNode); - std::set *> edgeSet; - edgeSet.insert(&edge); + std::list *> edgeSet; + edgeSet.push_back(&edge); CXXGRAPH::Graph graph(edgeSet); std::cout << "Test Print Adjacency Matrix" << std::endl; std::cout << graph.getAdjMatrix() << std::endl; @@ -131,10 +131,10 @@ TEST(GraphTest, adj_print_4) CXXGRAPH::UndirectedEdge edge1(1, pairNode); CXXGRAPH::UndirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedEdge edge3(3, node1, node3); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::cout << "Test Print Adjacency Matrix" << std::endl; std::cout << graph.getAdjMatrix() << std::endl; @@ -149,10 +149,10 @@ TEST(GraphTest, adj_print_5) CXXGRAPH::DirectedEdge edge1(1, pairNode); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::DirectedEdge edge3(3, node1, node3); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::cout << "Test Print Adjacency Matrix" << std::endl; std::cout << graph.getAdjMatrix() << std::endl; @@ -167,10 +167,10 @@ TEST(GraphTest, adj_print_6) CXXGRAPH::DirectedEdge edge1(1, pairNode); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedEdge edge3(3, node1, node3); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); std::cout << "Test Print Adjacency Matrix" << std::endl; std::cout << graph.getAdjMatrix() << std::endl; diff --git a/test/RWOutputTest.cpp b/test/RWOutputTest.cpp index c0ee3a205..67139a47d 100644 --- a/test/RWOutputTest.cpp +++ b/test/RWOutputTest.cpp @@ -16,10 +16,10 @@ TEST(RWOutputTest, test_1) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 1); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); int res = graph.writeToFile(); ASSERT_EQ(res, 0); @@ -37,10 +37,10 @@ TEST(RWOutputTest, test_2) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 5); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 4); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV); ASSERT_EQ(res, 0); @@ -58,10 +58,10 @@ TEST(RWOutputTest, test_3) CXXGRAPH::DirectedWeightedEdge edge1(1, pairNode, 5); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge1); - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge1); + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV, ".", "test_3"); ASSERT_EQ(res, 0); @@ -77,9 +77,9 @@ TEST(RWOutputTest, test_4) CXXGRAPH::Node node3(3, 3); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::OUT_1, "test_4"); ASSERT_EQ(res, -1); @@ -95,9 +95,9 @@ TEST(RWOutputTest, test_5) CXXGRAPH::Node node3(3, 3); CXXGRAPH::DirectedEdge edge2(2, node2, node3); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV, ".", "test_5", false, true, true); ASSERT_EQ(res, 0); @@ -113,9 +113,9 @@ TEST(RWOutputTest, test_6) CXXGRAPH::Node node3(3, 3); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV, ".", "test_6", false, false, true); ASSERT_EQ(res, 0); @@ -131,9 +131,9 @@ TEST(RWOutputTest, test_7) CXXGRAPH::Node node3(3, 3); CXXGRAPH::DirectedWeightedEdge edge2(2, node2, node3, 1); CXXGRAPH::UndirectedWeightedEdge edge3(3, node1, node3, 6); - std::set *> edgeSet; - edgeSet.insert(&edge2); - edgeSet.insert(&edge3); + std::list *> edgeSet; + edgeSet.push_back(&edge2); + edgeSet.push_back(&edge3); CXXGRAPH::Graph graph(edgeSet); int res = graph.writeToFile(CXXGRAPH::Graph::InputOutputFormat::STANDARD_CSV, ".", "test_7", false, true, false); ASSERT_EQ(res, 0);