Skip to content

Commit

Permalink
Formatted and trailed Whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigRazor authored Jun 28, 2021
1 parent 14e3b60 commit cc564bf
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 195 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ if(DEBUG)
-O0 #no optimization
-g #generate debug info
)
endif(DEBUG)

endif(DEBUG)

option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE)
Expand All @@ -36,12 +36,12 @@ if(CODE_COVERAGE)
"-fprofile-arcs"
"--coverage"
)
endif(CODE_COVERAGE)

endif(CODE_COVERAGE)

# add the library
add_executable(test_exe test/main.cpp

add_executable(test_exe test/main.cpp
test/NodeTest.cpp
test/EdgeTest.cpp
test/DirectedEdgeTest.cpp
Expand All @@ -58,9 +58,9 @@ add_executable(test_exe test/main.cpp
target_include_directories(test_exe PUBLIC
"${PROJECT_SOURCE_DIR}/include"
)
target_link_libraries(test_exe
libgtest.a
libgtest_main.a
target_link_libraries(test_exe
libgtest.a
libgtest_main.a
pthread )


Expand Down
6 changes: 3 additions & 3 deletions CXXGraphConfig.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// the configured options and settings for CXXGraph
#define CXXGraph_VERSION_MAJOR @CXXGraph_VERSION_MAJOR@
#define CXXGraph_VERSION_MINOR @CXXGraph_VERSION_MINOR@
#define CXXGraph_VERSION_PATCH @CXXGraph_VERSION_PATCH@
#define CXXGraph_VERSION_MAJOR @CXXGraph_VERSION_MAJOR @
#define CXXGraph_VERSION_MINOR @CXXGraph_VERSION_MINOR @
#define CXXGraph_VERSION_PATCH @CXXGraph_VERSION_PATCH @
39 changes: 22 additions & 17 deletions include/Graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,12 @@ namespace CXXGRAPH
int writeToStandardFile(std::string OFileName) const;

public:
typedef enum E_OutputFormat{
typedef enum E_OutputFormat
{
STANDARD,
OUT_1,
OUT_2
}OutputFormat;
} OutputFormat;

Graph() = default;
Graph(const std::set<const Edge<T> *> &edgeSet);
Expand All @@ -484,7 +485,7 @@ namespace CXXGRAPH
void removeEdge(unsigned long edgeId);
const std::set<const Node<T> *> getNodeSet() const;
const std::optional<const Edge<T> *> getEdge(unsigned long edgeId) const;
/*This function generate a list of adjacency matrix with every element of the matrix
/*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
*/
const AdjacencyMatrix<T> getAdjMatrix() const;
Expand Down Expand Up @@ -521,36 +522,36 @@ namespace CXXGRAPH
*/
const std::vector<Node<T>> depth_first_search(const Node<T> &start) const;

/**
/**
* \brief
* This function uses DFS to check for cycle in the graph.
* Pay Attention, this function work only with directed Graph
*
*
* @return true if a cycle is detected, else false. ( false is returned also if the graph in indirected)
*/
const bool isCyclicDirectedGraphDFS() const;

/**
/**
* \brief
* This function uses BFS to check for cycle in the graph.
* Pay Attention, this function work only with directed Graph
*
*
* @return true if a cycle is detected, else false. ( false is returned also if the graph in indirected)
*/
const bool isCyclicDirectedGraphBFS() const;

/**
* \brief
* This function checks if a graph is directed
*
*
* @return true if the graph is directed, else false.
*/
const bool isDirectedGraph() const;

/**
* \brief
* This function write the graph in an output file
*
*
* @param format The Output format of the file
* @param OFileName The Output File Name
* @return 0 if all OK, else return a negative value
Expand Down Expand Up @@ -631,14 +632,15 @@ namespace CXXGRAPH

//adjMatrix[nodeFrom.getId()].push_back(std::make_pair<const Node<T>,const Edge<T>>(nodeTo, edge));
}
template<typename T>

template <typename T>
int Graph<T>::writeToStandardFile(std::string OFileName) const
{
std::ofstream ofile;
ofile.open(OFileName);
auto printOut = [&ofile](const Edge<T> *e) { ofile << e->getId() << "," << e->getNodePair().first->getId() << "," << e->getNodePair().second->getId() << std::endl; };
std::for_each(edgeSet.cbegin(), edgeSet.cend(), printOut);
auto printOut = [&ofile](const Edge<T> *e)
{ ofile << e->getId() << "," << e->getNodePair().first->getId() << "," << e->getNodePair().second->getId() << std::endl; };
std::for_each(edgeSet.cbegin(), edgeSet.cend(), printOut);
ofile.close();
return 0;
}
Expand Down Expand Up @@ -1026,13 +1028,16 @@ namespace CXXGRAPH
//No Undirected Edge
return true;
}
template<typename T>

template <typename T>
int Graph<T>::writeToFile(OutputFormat format, std::string OFileName, bool compress) const
{
if( format == OutputFormat::STANDARD ){
if (format == OutputFormat::STANDARD)
{
return writeToStandardFile(OFileName);
}else{
}
else
{
//OUTPUT FORMAT NOT RECOGNIZED
return -1;
}
Expand Down
60 changes: 30 additions & 30 deletions test/BFSTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ TEST(BFSTest, test_1)
CXXGRAPH::Node<int> node2(2, 2);
CXXGRAPH::Node<int> node3(3, 3);
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::UndirectedWeightedEdge<int> edge3(3, node1, node3,6);
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGRAPH::UndirectedWeightedEdge<int> edge3(3, node1, node3, 6);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
CXXGRAPH::Graph<int> graph(edgeSet);
std::vector<CXXGRAPH::Node<int>> res= graph.breadth_first_search(node1);
ASSERT_EQ(res.size(),3);
std::vector<CXXGRAPH::Node<int>> res = graph.breadth_first_search(node1);
ASSERT_EQ(res.size(), 3);
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());
Expand All @@ -28,16 +28,16 @@ TEST(BFSTest, test_2)
CXXGRAPH::Node<int> node2(2, 2);
CXXGRAPH::Node<int> node3(3, 3);
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, node1, node3,6);
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge3(3, node1, node3, 6);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
CXXGRAPH::Graph<int> graph(edgeSet);
std::vector<CXXGRAPH::Node<int>> res= graph.breadth_first_search(node2);
ASSERT_EQ(res.size(),2);
std::vector<CXXGRAPH::Node<int>> res = graph.breadth_first_search(node2);
ASSERT_EQ(res.size(), 2);
ASSERT_FALSE(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());
Expand All @@ -49,16 +49,16 @@ TEST(BFSTest, test_3)
CXXGRAPH::Node<int> node2(2, 2);
CXXGRAPH::Node<int> node3(3, 3);
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::UndirectedWeightedEdge<int> edge3(3, node1, node3,6);
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGRAPH::UndirectedWeightedEdge<int> edge3(3, node1, node3, 6);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
CXXGRAPH::Graph<int> graph(edgeSet);
std::vector<CXXGRAPH::Node<int>> res= graph.breadth_first_search(node2);
ASSERT_EQ(res.size(),3);
std::vector<CXXGRAPH::Node<int>> res = graph.breadth_first_search(node2);
ASSERT_EQ(res.size(), 3);
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());
Expand All @@ -70,16 +70,16 @@ TEST(BFSTest, test_4)
CXXGRAPH::Node<int> node2(2, 2);
CXXGRAPH::Node<int> node3(3, 3);
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::UndirectedWeightedEdge<int> edge3(3, node1, node3,6);
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGRAPH::UndirectedWeightedEdge<int> edge3(3, node1, node3, 6);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
CXXGRAPH::Graph<int> graph(edgeSet);
std::vector<CXXGRAPH::Node<int>> res= graph.breadth_first_search(node3);
ASSERT_EQ(res.size(),3);
std::vector<CXXGRAPH::Node<int>> res = graph.breadth_first_search(node3);
ASSERT_EQ(res.size(), 3);
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());
Expand All @@ -91,16 +91,16 @@ TEST(BFSTest, test_5)
CXXGRAPH::Node<int> node2(2, 2);
CXXGRAPH::Node<int> node3(3, 3);
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, node1, node3,6);
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge3(3, node1, node3, 6);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
CXXGRAPH::Graph<int> graph(edgeSet);
std::vector<CXXGRAPH::Node<int>> res= graph.breadth_first_search(node3);
ASSERT_EQ(res.size(),1);
std::vector<CXXGRAPH::Node<int>> res = graph.breadth_first_search(node3);
ASSERT_EQ(res.size(), 1);
ASSERT_FALSE(std::find(res.begin(), res.end(), node1) != res.end());
ASSERT_FALSE(std::find(res.begin(), res.end(), node2) != res.end());
ASSERT_TRUE(std::find(res.begin(), res.end(), node3) != res.end());
Expand All @@ -113,16 +113,16 @@ TEST(BFSTest, test_6)
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, node1, node3,6);
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge3(3, node1, node3, 6);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
CXXGRAPH::Graph<int> graph(edgeSet);
std::vector<CXXGRAPH::Node<int>> res= graph.breadth_first_search(node4);
ASSERT_EQ(res.size(),0);
std::vector<CXXGRAPH::Node<int>> res = graph.breadth_first_search(node4);
ASSERT_EQ(res.size(), 0);
ASSERT_FALSE(std::find(res.begin(), res.end(), node1) != res.end());
ASSERT_FALSE(std::find(res.begin(), res.end(), node2) != res.end());
ASSERT_FALSE(std::find(res.begin(), res.end(), node3) != res.end());
Expand Down
Loading

0 comments on commit cc564bf

Please sign in to comment.