From 92a8ea5d753bee5ffb372f8db7052ce5bb24188f Mon Sep 17 00:00:00 2001 From: Simone Balducci <93096843+sbaldu@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:09:29 +0100 Subject: [PATCH] Create clang-format workflow (#390) * Create clang-format workflow * Fix typo * Formatting * Formatting --- .github/workflows/clang_format.yml | 26 ++++ benchmark/BellmanFord_BM.cpp | 2 +- benchmark/Boruvka_BM.cpp | 2 +- benchmark/Connectivity_BM.cpp | 2 +- benchmark/CycleCheck_BM.cpp | 2 +- benchmark/Dial_BM.cpp | 2 +- benchmark/Edge_BM.cpp | 2 +- benchmark/FloydWarshall_BM.cpp | 1 + benchmark/FordFulkerson_BM.cpp | 2 +- benchmark/Kruskal_BM.cpp | 2 +- benchmark/Node_BM.cpp | 2 +- benchmark/Partition_BM.cpp | 2 +- benchmark/Prim_BM.cpp | 2 +- benchmark/main.cpp | 2 +- examples/DialExample/dial_example.cpp | 2 +- examples/DijkstraExample/dijkstra_example.cpp | 1 - .../network_dynamics_example.cpp | 28 ++-- .../PartitionExample/partition_example.cpp | 15 +- include/CXXGraph/Edge/DirectedEdge_decl.h | 7 +- include/CXXGraph/Edge/DirectedEdge_impl.hpp | 10 +- .../CXXGraph/Edge/DirectedWeightedEdge_decl.h | 2 +- .../Edge/DirectedWeightedEdge_impl.hpp | 2 +- include/CXXGraph/Edge/UndirectedEdge_decl.h | 7 +- include/CXXGraph/Edge/UndirectedEdge_impl.hpp | 5 +- .../Edge/UndirectedWeightedEdge_impl.hpp | 2 +- .../Graph/Algorithm/BestFirstSearch_impl.hpp | 9 +- .../CXXGraph/Graph/Algorithm/Boruvka_impl.hpp | 5 +- .../Algorithm/BreadthFirstSearch_impl.hpp | 1 - .../Graph/Algorithm/DepthFirstSearch_impl.hpp | 2 +- .../Graph/Algorithm/Kosaraju_impl.hpp | 3 +- .../CXXGraph/Graph/Algorithm/Tarjan_impl.hpp | 6 +- include/CXXGraph/Graph/Graph.h | 2 +- include/CXXGraph/Graph/IO/IOUtility_impl.hpp | 7 +- .../CXXGraph/Graph/IO/InputOperation_impl.hpp | 2 - .../Graph/IO/OutputOperation_impl.hpp | 1 - include/CXXGraph/Node/Node_impl.hpp | 3 +- .../CoordinatedPartitionState.hpp | 16 +- .../Partitioning/CoordinatedRecord.hpp | 2 +- include/CXXGraph/Partitioning/EBV.hpp | 12 +- .../Partitioning/EdgeBalancedVertexCut.hpp | 9 +- .../CXXGraph/Partitioning/GreedyVertexCut.hpp | 12 +- include/CXXGraph/Partitioning/HDRF.hpp | 10 +- include/CXXGraph/Partitioning/Partition.hpp | 33 ++-- .../CXXGraph/Partitioning/PartitionState.hpp | 3 +- .../Partitioning/PartitionStrategy.hpp | 7 +- include/CXXGraph/Partitioning/Partitioner.hpp | 46 +++--- .../Partitioning/PartitionerThread.hpp | 10 +- .../Partitioning/WeightBalancedLibra.hpp | 5 +- include/CXXGraph/Utility/PointerHash.hpp | 10 +- include/CXXGraph/Utility/Reader.hpp | 2 +- include/CXXGraph/Utility/Typedef.hpp | 23 ++- include/CXXGraph/Utility/id_t.hpp | 11 +- test/BFSTest.cpp | 13 +- test/BellmanFordTest.cpp | 5 +- test/BestFirstSearchTest.cpp | 4 +- test/BoruvkaTest.cpp | 5 +- test/ConnectivityTest.cpp | 5 +- test/CycleCheckTest.cpp | 5 +- test/DOTTest.cpp | 4 +- test/DialTest.cpp | 5 +- test/DijkstraTest.cpp | 85 +++++----- test/DirectedEdgeTest.cpp | 12 +- test/DirectedWeightedEdgeTest.cpp | 12 +- test/EdgeTest.cpp | 12 +- test/EulerPathTest.cpp | 5 +- test/FWTest.cpp | 4 +- test/FordFulkersonTest.cpp | 5 +- test/GraphSlicingTest.cpp | 5 +- test/KahnTest.cpp | 5 +- test/KosarajuTest.cpp | 11 +- test/KruskalTest.cpp | 5 +- test/MTXTest.cpp | 46 +++--- test/NodeTest.cpp | 4 +- test/PrimTest.cpp | 5 +- test/RWOutputTest.cpp | 64 ++++---- test/TarjanTest.cpp | 145 +++++++++--------- test/TopologicalSortTest.cpp | 5 +- test/TransitiveReductionTest.cpp | 4 +- test/UndirectedEdgeTest.cpp | 12 +- test/UndirectedWeightedEdgeTest.cpp | 12 +- test/UnionFindTest.cpp | 4 +- 81 files changed, 483 insertions(+), 409 deletions(-) create mode 100644 .github/workflows/clang_format.yml mode change 100755 => 100644 include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/CoordinatedRecord.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/EBV.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/EdgeBalancedVertexCut.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/GreedyVertexCut.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/HDRF.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/Partition.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/PartitionState.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/PartitionStrategy.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/Partitioner.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/PartitionerThread.hpp mode change 100755 => 100644 include/CXXGraph/Partitioning/WeightBalancedLibra.hpp mode change 100755 => 100644 include/CXXGraph/Utility/PointerHash.hpp mode change 100755 => 100644 include/CXXGraph/Utility/Reader.hpp mode change 100755 => 100644 include/CXXGraph/Utility/Typedef.hpp diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml new file mode 100644 index 000000000..3e3d1f91c --- /dev/null +++ b/.github/workflows/clang_format.yml @@ -0,0 +1,26 @@ +name: clang-format Check + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + formatting-check: + name: Formatting Check + runs-on: ubuntu-latest + strategy: + matrix: + path: + - 'benchmark' + - 'examples' + - 'include/CXXGraph' + - 'test' + steps: + - uses: actions/checkout@v3 + - name: Run clang-format style check + uses: jidicula/clang-format-action@v4.11.0 + with: + clang-format-version: '16' + check-path: ${{ matrix.path }} diff --git a/benchmark/BellmanFord_BM.cpp b/benchmark/BellmanFord_BM.cpp index d3e349aa3..8573b894b 100644 --- a/benchmark/BellmanFord_BM.cpp +++ b/benchmark/BellmanFord_BM.cpp @@ -30,4 +30,4 @@ static void BellmanFord_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(BellmanFord_FromReadedCitHep); \ No newline at end of file +BENCHMARK(BellmanFord_FromReadedCitHep); diff --git a/benchmark/Boruvka_BM.cpp b/benchmark/Boruvka_BM.cpp index fbc52ed34..2d5d77ae4 100644 --- a/benchmark/Boruvka_BM.cpp +++ b/benchmark/Boruvka_BM.cpp @@ -26,4 +26,4 @@ static void Boruvka_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(Boruvka_FromReadedCitHep); \ No newline at end of file +BENCHMARK(Boruvka_FromReadedCitHep); diff --git a/benchmark/Connectivity_BM.cpp b/benchmark/Connectivity_BM.cpp index c5258f31f..234e9111c 100644 --- a/benchmark/Connectivity_BM.cpp +++ b/benchmark/Connectivity_BM.cpp @@ -53,4 +53,4 @@ static void StrongConnectivity_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(StrongConnectivity_FromReadedCitHep); \ No newline at end of file +BENCHMARK(StrongConnectivity_FromReadedCitHep); diff --git a/benchmark/CycleCheck_BM.cpp b/benchmark/CycleCheck_BM.cpp index 785555d2f..93a0f43c9 100644 --- a/benchmark/CycleCheck_BM.cpp +++ b/benchmark/CycleCheck_BM.cpp @@ -53,4 +53,4 @@ static void CycleCheckDFS_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(CycleCheckDFS_FromReadedCitHep); \ No newline at end of file +BENCHMARK(CycleCheckDFS_FromReadedCitHep); diff --git a/benchmark/Dial_BM.cpp b/benchmark/Dial_BM.cpp index 5d9cecf4e..b70c653c5 100644 --- a/benchmark/Dial_BM.cpp +++ b/benchmark/Dial_BM.cpp @@ -27,4 +27,4 @@ static void Dial_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(Dial_FromReadedCitHep); \ No newline at end of file +BENCHMARK(Dial_FromReadedCitHep); diff --git a/benchmark/Edge_BM.cpp b/benchmark/Edge_BM.cpp index bfeec4f96..95f8e0cfa 100644 --- a/benchmark/Edge_BM.cpp +++ b/benchmark/Edge_BM.cpp @@ -47,4 +47,4 @@ static void NodeGetNodePair(benchmark::State &state) { e.getNodePair(); } } -BENCHMARK(NodeGetNodePair); \ No newline at end of file +BENCHMARK(NodeGetNodePair); diff --git a/benchmark/FloydWarshall_BM.cpp b/benchmark/FloydWarshall_BM.cpp index 25f665eff..127d8c49d 100644 --- a/benchmark/FloydWarshall_BM.cpp +++ b/benchmark/FloydWarshall_BM.cpp @@ -1,4 +1,5 @@ #include + #include #include "CXXGraph/CXXGraph.hpp" diff --git a/benchmark/FordFulkerson_BM.cpp b/benchmark/FordFulkerson_BM.cpp index 178e5c90b..6afd9699d 100644 --- a/benchmark/FordFulkerson_BM.cpp +++ b/benchmark/FordFulkerson_BM.cpp @@ -31,4 +31,4 @@ static void FordFulkerson_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(FordFulkerson_FromReadedCitHep); \ No newline at end of file +BENCHMARK(FordFulkerson_FromReadedCitHep); diff --git a/benchmark/Kruskal_BM.cpp b/benchmark/Kruskal_BM.cpp index a91127e7c..a6d29fa0e 100644 --- a/benchmark/Kruskal_BM.cpp +++ b/benchmark/Kruskal_BM.cpp @@ -26,4 +26,4 @@ static void Kruskal_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(Kruskal_FromReadedCitHep); \ No newline at end of file +BENCHMARK(Kruskal_FromReadedCitHep); diff --git a/benchmark/Node_BM.cpp b/benchmark/Node_BM.cpp index 350bbd96a..a1604c20b 100644 --- a/benchmark/Node_BM.cpp +++ b/benchmark/Node_BM.cpp @@ -33,4 +33,4 @@ static void NodeGetData(benchmark::State &state) { n1.getData(); } } -BENCHMARK(NodeGetData); \ No newline at end of file +BENCHMARK(NodeGetData); diff --git a/benchmark/Partition_BM.cpp b/benchmark/Partition_BM.cpp index 5f2f0e46a..c4c6d69c8 100644 --- a/benchmark/Partition_BM.cpp +++ b/benchmark/Partition_BM.cpp @@ -113,4 +113,4 @@ static void PartitionEBV_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(PartitionEBV_FromReadedCitHep); \ No newline at end of file +BENCHMARK(PartitionEBV_FromReadedCitHep); diff --git a/benchmark/Prim_BM.cpp b/benchmark/Prim_BM.cpp index f4a34457f..4b1d75682 100644 --- a/benchmark/Prim_BM.cpp +++ b/benchmark/Prim_BM.cpp @@ -26,4 +26,4 @@ static void Prim_FromReadedCitHep(benchmark::State &state) { } } -BENCHMARK(Prim_FromReadedCitHep); \ No newline at end of file +BENCHMARK(Prim_FromReadedCitHep); diff --git a/benchmark/main.cpp b/benchmark/main.cpp index 2a3fbf94a..71fefa047 100644 --- a/benchmark/main.cpp +++ b/benchmark/main.cpp @@ -1,3 +1,3 @@ #include -BENCHMARK_MAIN(); \ No newline at end of file +BENCHMARK_MAIN(); diff --git a/examples/DialExample/dial_example.cpp b/examples/DialExample/dial_example.cpp index 0b06dc361..bbcde54c9 100644 --- a/examples/DialExample/dial_example.cpp +++ b/examples/DialExample/dial_example.cpp @@ -1,7 +1,7 @@ #include -#include #include +#include using std::make_shared; diff --git a/examples/DijkstraExample/dijkstra_example.cpp b/examples/DijkstraExample/dijkstra_example.cpp index bd482ad65..4c376f207 100644 --- a/examples/DijkstraExample/dijkstra_example.cpp +++ b/examples/DijkstraExample/dijkstra_example.cpp @@ -1,5 +1,4 @@ #include - #include using std::make_shared; diff --git a/examples/NetworkDynamicsExample/network_dynamics_example.cpp b/examples/NetworkDynamicsExample/network_dynamics_example.cpp index 522e11df9..5d7f17124 100644 --- a/examples/NetworkDynamicsExample/network_dynamics_example.cpp +++ b/examples/NetworkDynamicsExample/network_dynamics_example.cpp @@ -1,7 +1,7 @@ -#include "CXXGraph/CXXGraph.hpp" - #include +#include "CXXGraph/CXXGraph.hpp" + using std::make_shared; int main() { @@ -25,11 +25,12 @@ int main() { auto degreeMatrix = graph.getDegreeMatrix(); for (const auto& nodePair : *degreeMatrix) { - const CXXGraph::shared>& node = nodePair.first; - const std::vector& degrees = nodePair.second; + const CXXGraph::shared>& node = nodePair.first; + const std::vector& degrees = nodePair.second; - std::cout << "Node: " << node->getId() << ", Degree: " << degrees[0] << "\n"; - } + std::cout << "Node: " << node->getId() << ", Degree: " << degrees[0] + << "\n"; + } auto laplacianMatrix = graph.getLaplacianMatrix(); for (const auto& nodePair : *laplacianMatrix) { const auto& node = nodePair.first; @@ -37,11 +38,13 @@ int main() { std::cout << "Node " << node->getId() << " connected to:" << std::endl; for (const auto& neighbor : neighbors) { - if (neighbor.first == node) { - std::cout << " -> Itself" << std::endl; - } else { - std::cout << " -> Node " << neighbor.first->getId() << " with Edge ID " << (neighbor.second ? neighbor.second->getId() : -1) << std::endl; - } + if (neighbor.first == node) { + std::cout << " -> Itself" << std::endl; + } else { + std::cout << " -> Node " << neighbor.first->getId() << " with Edge ID " + << (neighbor.second ? neighbor.second->getId() : -1) + << std::endl; + } } std::cout << std::endl; } @@ -53,7 +56,8 @@ int main() { std::cout << "Transitions from Node " << node->getId() << ":" << std::endl; for (const auto& transition : transitions) { - std::cout << " -> To Node " << transition.first->getId() << " with Probability " << transition.second << std::endl; + std::cout << " -> To Node " << transition.first->getId() + << " with Probability " << transition.second << std::endl; } std::cout << std::endl; } diff --git a/examples/PartitionExample/partition_example.cpp b/examples/PartitionExample/partition_example.cpp index 2c3b0e9d5..75e3cbd8a 100644 --- a/examples/PartitionExample/partition_example.cpp +++ b/examples/PartitionExample/partition_example.cpp @@ -19,14 +19,17 @@ int main() { // std::cout << *cit_graph_ptr << std::endl; std::cout << cit_graph_ptr->getEdgeSet().size() << std::endl; std::cout << cit_graph_ptr->getNodeSet().size() << std::endl; - auto partitionedTwo = CXXGraph::Partitioning::Partitioner::partitionGraph( *cit_graph_ptr, - CXXGraph::Partitioning::HDRF_ALG, 2, 1, 1, 1, 4); + auto partitionedTwo = + CXXGraph::Partitioning::Partitioner::partitionGraph( + *cit_graph_ptr, CXXGraph::Partitioning::HDRF_ALG, 2, 1, 1, 1, 4); std::cout << "end partition two" << std::endl; - auto partitionedFour = CXXGraph::Partitioning::Partitioner::partitionGraph( *cit_graph_ptr, - CXXGraph::Partitioning::HDRF_ALG, 4, 1, 1, 1, 4); + auto partitionedFour = + CXXGraph::Partitioning::Partitioner::partitionGraph( + *cit_graph_ptr, CXXGraph::Partitioning::HDRF_ALG, 4, 1, 1, 1, 4); std::cout << "end partition four" << std::endl; - auto partitionedEight = CXXGraph::Partitioning::Partitioner::partitionGraph( *cit_graph_ptr, - CXXGraph::Partitioning::HDRF_ALG, 8, 1, 1, 1, 4); + auto partitionedEight = + CXXGraph::Partitioning::Partitioner::partitionGraph( + *cit_graph_ptr, CXXGraph::Partitioning::HDRF_ALG, 8, 1, 1, 1, 4); std::cout << "end partition eight" << std::endl; auto statsTwo = CXXGraph::Partitioning::getPartitionStats(partitionedTwo); auto statsFour = CXXGraph::Partitioning::getPartitionStats(partitionedFour); diff --git a/include/CXXGraph/Edge/DirectedEdge_decl.h b/include/CXXGraph/Edge/DirectedEdge_decl.h index a612eafb5..12329ac3a 100644 --- a/include/CXXGraph/Edge/DirectedEdge_decl.h +++ b/include/CXXGraph/Edge/DirectedEdge_decl.h @@ -29,7 +29,7 @@ namespace CXXGraph { template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; template class UndirectedEdge; @@ -48,8 +48,9 @@ class DirectedEdge : public Edge { shared> node2); DirectedEdge(const CXXGraph::id_t id, const std::pair *, const Node *> &nodepair); - DirectedEdge(const CXXGraph::id_t id, - const std::pair>, shared>> &nodepair); + DirectedEdge( + const CXXGraph::id_t id, + const std::pair>, shared>> &nodepair); DirectedEdge(const Edge &edge); virtual ~DirectedEdge() = default; const Node &getFrom() const; diff --git a/include/CXXGraph/Edge/DirectedEdge_impl.hpp b/include/CXXGraph/Edge/DirectedEdge_impl.hpp index 46462752e..1ac736044 100644 --- a/include/CXXGraph/Edge/DirectedEdge_impl.hpp +++ b/include/CXXGraph/Edge/DirectedEdge_impl.hpp @@ -25,9 +25,9 @@ #include "DirectedEdge_decl.h" namespace CXXGraph { - -using std::make_unique; + using std::make_shared; +using std::make_unique; template DirectedEdge::DirectedEdge(const CXXGraph::id_t id, const Node &node1, @@ -35,8 +35,10 @@ DirectedEdge::DirectedEdge(const CXXGraph::id_t id, const Node &node1, : Edge(id, node1, node2) {} template -DirectedEdge::DirectedEdge(const CXXGraph::id_t id, shared> node1, - shared> node2) : Edge(id, node1, node2) {} +DirectedEdge::DirectedEdge(const CXXGraph::id_t id, + shared> node1, + shared> node2) + : Edge(id, node1, node2) {} template DirectedEdge::DirectedEdge( diff --git a/include/CXXGraph/Edge/DirectedWeightedEdge_decl.h b/include/CXXGraph/Edge/DirectedWeightedEdge_decl.h index cea8cd2ff..3a08ff063 100644 --- a/include/CXXGraph/Edge/DirectedWeightedEdge_decl.h +++ b/include/CXXGraph/Edge/DirectedWeightedEdge_decl.h @@ -29,7 +29,7 @@ namespace CXXGraph { template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; // Foward Declaration template diff --git a/include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp b/include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp index c349450fc..723ebd49c 100644 --- a/include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp +++ b/include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp @@ -26,8 +26,8 @@ namespace CXXGraph { -using std::make_unique; using std::make_shared; +using std::make_unique; template DirectedWeightedEdge::DirectedWeightedEdge(const CXXGraph::id_t id, diff --git a/include/CXXGraph/Edge/UndirectedEdge_decl.h b/include/CXXGraph/Edge/UndirectedEdge_decl.h index efd7b2f36..013d832eb 100644 --- a/include/CXXGraph/Edge/UndirectedEdge_decl.h +++ b/include/CXXGraph/Edge/UndirectedEdge_decl.h @@ -29,7 +29,7 @@ namespace CXXGraph { template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; template class UndirectedEdge; @@ -47,8 +47,9 @@ class UndirectedEdge : public Edge { shared> node2); UndirectedEdge(const CXXGraph::id_t id, const std::pair *, const Node *> &nodepair); - UndirectedEdge(const CXXGraph::id_t id, - const std::pair>, shared>> &nodepair); + UndirectedEdge( + const CXXGraph::id_t id, + const std::pair>, shared>> &nodepair); UndirectedEdge(const Edge &edge); virtual ~UndirectedEdge() = default; const Node &getNode1() const; diff --git a/include/CXXGraph/Edge/UndirectedEdge_impl.hpp b/include/CXXGraph/Edge/UndirectedEdge_impl.hpp index 2293e5a53..29510ab07 100644 --- a/include/CXXGraph/Edge/UndirectedEdge_impl.hpp +++ b/include/CXXGraph/Edge/UndirectedEdge_impl.hpp @@ -26,8 +26,8 @@ namespace CXXGraph { -using std::make_unique; using std::make_shared; +using std::make_unique; template UndirectedEdge::UndirectedEdge(const CXXGraph::id_t id, const Node &node1, @@ -35,7 +35,8 @@ UndirectedEdge::UndirectedEdge(const CXXGraph::id_t id, const Node &node1, : Edge(id, node1, node2) {} template -UndirectedEdge::UndirectedEdge(const CXXGraph::id_t id, shared> node1, +UndirectedEdge::UndirectedEdge(const CXXGraph::id_t id, + shared> node1, shared> node2) : Edge(id, node1, node2) {} diff --git a/include/CXXGraph/Edge/UndirectedWeightedEdge_impl.hpp b/include/CXXGraph/Edge/UndirectedWeightedEdge_impl.hpp index b93805b35..61f331eb8 100644 --- a/include/CXXGraph/Edge/UndirectedWeightedEdge_impl.hpp +++ b/include/CXXGraph/Edge/UndirectedWeightedEdge_impl.hpp @@ -26,8 +26,8 @@ namespace CXXGraph { -using std::make_unique; using std::make_shared; +using std::make_unique; template UndirectedWeightedEdge::UndirectedWeightedEdge(const CXXGraph::id_t id, diff --git a/include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp b/include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp index 38bafc77e..d61aed940 100644 --- a/include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp @@ -22,12 +22,13 @@ #pragma once -#include "CXXGraph/Graph/Graph_decl.h" -#include -#include -#include #include #include +#include +#include +#include + +#include "CXXGraph/Graph/Graph_decl.h" namespace CXXGraph { template diff --git a/include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp b/include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp index b43853977..39b2cd6bc 100644 --- a/include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Boruvka_impl.hpp @@ -22,11 +22,12 @@ #pragma once -#include "CXXGraph/Graph/Graph_decl.h" #include +#include "CXXGraph/Graph/Graph_decl.h" + namespace CXXGraph { - + template const MstResult Graph::boruvka() const { MstResult result; diff --git a/include/CXXGraph/Graph/Algorithm/BreadthFirstSearch_impl.hpp b/include/CXXGraph/Graph/Algorithm/BreadthFirstSearch_impl.hpp index 08ec41058..82d0b33f0 100644 --- a/include/CXXGraph/Graph/Algorithm/BreadthFirstSearch_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/BreadthFirstSearch_impl.hpp @@ -64,6 +64,5 @@ const std::vector> Graph::breadth_first_search( return visited; } - } // namespace CXXGraph #endif // __CXXGRAPH_BREADTHFIRSTSEARCH_IMPL_H__ \ No newline at end of file diff --git a/include/CXXGraph/Graph/Algorithm/DepthFirstSearch_impl.hpp b/include/CXXGraph/Graph/Algorithm/DepthFirstSearch_impl.hpp index 82a0553da..6f3bcf105 100644 --- a/include/CXXGraph/Graph/Algorithm/DepthFirstSearch_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/DepthFirstSearch_impl.hpp @@ -25,7 +25,7 @@ #include "CXXGraph/Graph/Graph_decl.h" namespace CXXGraph { - + template const std::vector> Graph::depth_first_search( const Node &start) const { diff --git a/include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp b/include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp index 6e28acd7a..faad5cb80 100644 --- a/include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp @@ -22,9 +22,10 @@ #pragma once -#include "CXXGraph/Graph/Graph_decl.h" #include +#include "CXXGraph/Graph/Graph_decl.h" + namespace CXXGraph { template diff --git a/include/CXXGraph/Graph/Algorithm/Tarjan_impl.hpp b/include/CXXGraph/Graph/Algorithm/Tarjan_impl.hpp index a2fd2ec6b..2aae4dec4 100644 --- a/include/CXXGraph/Graph/Algorithm/Tarjan_impl.hpp +++ b/include/CXXGraph/Graph/Algorithm/Tarjan_impl.hpp @@ -80,11 +80,11 @@ const TarjanResult Graph::tarjan(const unsigned int typeMask) const { if (typeMask & TARJAN_FIND_VBCC) { vbccNodeStack.emplace(*curNode); } - // travel the neighbors + // travel the neighbors if (cachedAdjMatrix->find(curNode) != cachedAdjMatrix->end()) { - int numSon = 0; + int numSon = 0; bool nodeIsAdded = - false; // whether a node has been marked as a cut vertice + false; // whether a node has been marked as a cut vertice for (const auto &[neighborNode, edge] : cachedAdjMatrix->at(curNode)) { if (!discoveryTime.count(neighborNode->getId())) { diff --git a/include/CXXGraph/Graph/Graph.h b/include/CXXGraph/Graph/Graph.h index 4691f67e6..7792f4fb1 100644 --- a/include/CXXGraph/Graph/Graph.h +++ b/include/CXXGraph/Graph/Graph.h @@ -22,7 +22,7 @@ #include "CXXGraph/Graph/Graph_impl.hpp" -//Algorithm +// Algorithm #include "CXXGraph/Graph/Algorithm/BellmanFord_impl.hpp" #include "CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp" #include "CXXGraph/Graph/Algorithm/Boruvka_impl.hpp" diff --git a/include/CXXGraph/Graph/IO/IOUtility_impl.hpp b/include/CXXGraph/Graph/IO/IOUtility_impl.hpp index 767ba1edd..eeb0aee78 100644 --- a/include/CXXGraph/Graph/IO/IOUtility_impl.hpp +++ b/include/CXXGraph/Graph/IO/IOUtility_impl.hpp @@ -37,8 +37,6 @@ std::optional> Graph::getExtenstionAndSeparator( } } - - // This ctype facet classifies ',' and '\t' as whitespace struct csv_whitespace : std::ctype { static const mask *make_table() { @@ -49,7 +47,8 @@ struct csv_whitespace : std::ctype { v[' '] &= ~space; // space will not be classified as whitespace return &v[0]; } - explicit csv_whitespace(std::size_t refs = 0) : ctype(make_table(), false, refs) {} + explicit csv_whitespace(std::size_t refs = 0) + : ctype(make_table(), false, refs) {} }; #ifdef WITH_COMPRESSION @@ -89,7 +88,7 @@ int Graph::decompressFile(const std::string &inputFile, // printf("Error: Failed to gzopen %s\n", inputFile.c_str()); return -1; } - unsigned char unzipBuffer[8192]; + unsigned char unzipBuffer[8192]; std::vector unzippedData; std::ofstream ofs; ofs.open(outputFile); diff --git a/include/CXXGraph/Graph/IO/InputOperation_impl.hpp b/include/CXXGraph/Graph/IO/InputOperation_impl.hpp index 8c52f24c7..182ad7746 100644 --- a/include/CXXGraph/Graph/IO/InputOperation_impl.hpp +++ b/include/CXXGraph/Graph/IO/InputOperation_impl.hpp @@ -375,8 +375,6 @@ void Graph::readGraphFromStream(std::istream &iGraph, recreateGraph(edgeMap, edgeDirectedMap, nodeFeatMap, edgeWeightMap); } - - template void Graph::recreateGraph( std::unordered_map> diff --git a/include/CXXGraph/Graph/IO/OutputOperation_impl.hpp b/include/CXXGraph/Graph/IO/OutputOperation_impl.hpp index 99d5ef95e..fc3dae71c 100644 --- a/include/CXXGraph/Graph/IO/OutputOperation_impl.hpp +++ b/include/CXXGraph/Graph/IO/OutputOperation_impl.hpp @@ -26,7 +26,6 @@ namespace CXXGraph { - template int Graph::writeToFile(InputOutputFormat format, const std::string &workingDir, diff --git a/include/CXXGraph/Node/Node_impl.hpp b/include/CXXGraph/Node/Node_impl.hpp index 3b25ba0f5..eb6905c2c 100644 --- a/include/CXXGraph/Node/Node_impl.hpp +++ b/include/CXXGraph/Node/Node_impl.hpp @@ -20,9 +20,10 @@ #ifndef __CXXGRAPH_NODE_IMPL_H__ #define __CXXGRAPH_NODE_IMPL_H__ -#include "Node_decl.h" #include +#include "Node_decl.h" + namespace CXXGraph { template diff --git a/include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp b/include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp old mode 100755 new mode 100644 index 3005cd778..9e126a72a --- a/include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp +++ b/include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp @@ -27,10 +27,10 @@ #include #include -#include "CoordinatedRecord.hpp" #include "CXXGraph/Edge/Edge.h" -#include "PartitionState.hpp" #include "CXXGraph/Partitioning/Utility/Globals.hpp" +#include "CoordinatedRecord.hpp" +#include "PartitionState.hpp" #include "Record.hpp" namespace CXXGraph { @@ -38,10 +38,10 @@ namespace CXXGraph { template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; namespace Partitioning { template @@ -134,8 +134,8 @@ int CoordinatedPartitionState::getMachineLoadVertices(const int m) const { return (int)machines_load_vertices.at(m); } template -void CoordinatedPartitionState::incrementMachineLoad(const int m, - shared> e) { +void CoordinatedPartitionState::incrementMachineLoad( + const int m, shared> e) { std::lock_guard lock(*machines_load_edges_mutex); machines_load_edges[m] = machines_load_edges[m] + 1; int new_value = machines_load_edges.at(m); @@ -145,8 +145,8 @@ void CoordinatedPartitionState::incrementMachineLoad(const int m, partition_map[m]->addEdge(e); } template -void CoordinatedPartitionState::incrementMachineWeight(const int m, - shared> e) { +void CoordinatedPartitionState::incrementMachineWeight( + const int m, shared> e) { std::lock_guard lock(*machines_weight_edges_mutex); double edge_weight = CXXGraph::NEGLIGIBLE_WEIGHT; if (e->isWeighted().has_value() && e->isWeighted().value()) { diff --git a/include/CXXGraph/Partitioning/CoordinatedRecord.hpp b/include/CXXGraph/Partitioning/CoordinatedRecord.hpp old mode 100755 new mode 100644 index 0d26b6104..43094c04f --- a/include/CXXGraph/Partitioning/CoordinatedRecord.hpp +++ b/include/CXXGraph/Partitioning/CoordinatedRecord.hpp @@ -24,8 +24,8 @@ #include -#include "Record.hpp" #include "CXXGraph/Utility/Typedef.hpp" +#include "Record.hpp" namespace CXXGraph { namespace Partitioning { diff --git a/include/CXXGraph/Partitioning/EBV.hpp b/include/CXXGraph/Partitioning/EBV.hpp old mode 100755 new mode 100644 index 4a1d3a0b9..0bbf36c22 --- a/include/CXXGraph/Partitioning/EBV.hpp +++ b/include/CXXGraph/Partitioning/EBV.hpp @@ -27,18 +27,18 @@ #include #include "CXXGraph/Edge/Edge.h" -#include "PartitionStrategy.hpp" #include "CXXGraph/Partitioning/Utility/Globals.hpp" +#include "PartitionStrategy.hpp" namespace CXXGraph { // Smart pointers alias template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; namespace Partitioning { /** @@ -57,7 +57,8 @@ class EBV : public PartitionStrategy { explicit EBV(const Globals &G); ~EBV(); - void performStep(shared> e, shared> Sstate) override; + void performStep(shared> e, + shared> Sstate) override; }; template EBV::EBV(const Globals &G) : GLOBALS(G) { @@ -66,7 +67,8 @@ EBV::EBV(const Globals &G) : GLOBALS(G) { template EBV::~EBV() {} template -void EBV::performStep(shared> e, shared> state){ +void EBV::performStep(shared> e, + shared> state) { GLOBALS.edgeAnalyzed++; int P = GLOBALS.numberOfPartition; diff --git a/include/CXXGraph/Partitioning/EdgeBalancedVertexCut.hpp b/include/CXXGraph/Partitioning/EdgeBalancedVertexCut.hpp old mode 100755 new mode 100644 index 9baeed4aa..593687650 --- a/include/CXXGraph/Partitioning/EdgeBalancedVertexCut.hpp +++ b/include/CXXGraph/Partitioning/EdgeBalancedVertexCut.hpp @@ -26,18 +26,18 @@ #include #include "CXXGraph/Edge/Edge.h" -#include "PartitionStrategy.hpp" #include "CXXGraph/Partitioning/Utility/Globals.hpp" +#include "PartitionStrategy.hpp" namespace CXXGraph { // Smart pointers alias template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; namespace Partitioning { /** @@ -55,7 +55,8 @@ class EdgeBalancedVertexCut : public PartitionStrategy { explicit EdgeBalancedVertexCut(const Globals &G); ~EdgeBalancedVertexCut(); - void performStep(shared> e, shared> Sstate) override; + void performStep(shared> e, + shared> Sstate) override; }; template EdgeBalancedVertexCut::EdgeBalancedVertexCut(const Globals &G) : GLOBALS(G) { diff --git a/include/CXXGraph/Partitioning/GreedyVertexCut.hpp b/include/CXXGraph/Partitioning/GreedyVertexCut.hpp old mode 100755 new mode 100644 index 7fd181205..679ef384d --- a/include/CXXGraph/Partitioning/GreedyVertexCut.hpp +++ b/include/CXXGraph/Partitioning/GreedyVertexCut.hpp @@ -23,23 +23,24 @@ #include #pragma once +#include + #include #include -#include #include "CXXGraph/Edge/Edge.h" -#include "PartitionStrategy.hpp" #include "CXXGraph/Partitioning/Utility/Globals.hpp" +#include "PartitionStrategy.hpp" namespace CXXGraph { // Smart pointers alias template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; namespace Partitioning { /** @@ -56,7 +57,8 @@ class GreedyVertexCut : public PartitionStrategy { explicit GreedyVertexCut(const Globals &G); ~GreedyVertexCut(); - void performStep(shared> e, shared> Sstate) override; + void performStep(shared> e, + shared> Sstate) override; }; template diff --git a/include/CXXGraph/Partitioning/HDRF.hpp b/include/CXXGraph/Partitioning/HDRF.hpp old mode 100755 new mode 100644 index bf968f953..6e7849690 --- a/include/CXXGraph/Partitioning/HDRF.hpp +++ b/include/CXXGraph/Partitioning/HDRF.hpp @@ -27,8 +27,8 @@ #include #include "CXXGraph/Edge/Edge.h" -#include "PartitionStrategy.hpp" #include "CXXGraph/Partitioning/Utility/Globals.hpp" +#include "PartitionStrategy.hpp" namespace CXXGraph { // Smart pointers alias @@ -37,8 +37,8 @@ using unique = std::unique_ptr; template using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; namespace Partitioning { /** @@ -57,7 +57,8 @@ class HDRF : public PartitionStrategy { explicit HDRF(const Globals &G); ~HDRF(); - void performStep(shared> e, shared> Sstate) override; + void performStep(shared> e, + shared> Sstate) override; }; template HDRF::HDRF(const Globals &G) : GLOBALS(G) { @@ -66,7 +67,8 @@ HDRF::HDRF(const Globals &G) : GLOBALS(G) { template HDRF::~HDRF() {} template -void HDRF::performStep(shared> e, shared> state) { +void HDRF::performStep(shared> e, + shared> state) { int P = GLOBALS.numberOfPartition; double lambda = GLOBALS.param1; double epsilon = GLOBALS.param2; diff --git a/include/CXXGraph/Partitioning/Partition.hpp b/include/CXXGraph/Partitioning/Partition.hpp old mode 100755 new mode 100644 index 64005703e..4c65a8c09 --- a/include/CXXGraph/Partitioning/Partition.hpp +++ b/include/CXXGraph/Partitioning/Partition.hpp @@ -26,18 +26,18 @@ #include #include -#include "PartitioningStats.hpp" #include "CXXGraph/Utility/Typedef.hpp" +#include "PartitioningStats.hpp" namespace CXXGraph { // Smart pointers alias template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; template class Graph; @@ -293,7 +293,8 @@ unsigned int getNumberOfNodes(const PartitionMap &partitionMap) { std::unordered_set>, nodeHash> nodeSet; for (const auto &it : partitionMap) { - const std::unordered_set>, nodeHash> partitionNodeSet = it.second->getNodeSet(); + const std::unordered_set>, nodeHash> + partitionNodeSet = it.second->getNodeSet(); for (const auto &it2 : partitionNodeSet) { // if (std::find_if(nodeSet.begin(), nodeSet.end(), [it2](const Node // *node) @@ -337,15 +338,23 @@ std::ostream &operator<<(std::ostream &os, const Partition &partition) { (*it)->isDirected().value()) && ((*it)->isWeighted().has_value() && (*it)->isWeighted().value())) { - os << *std::static_pointer_cast>(*it) << "\n"; - } else if (((*it)->isDirected().has_value() && (*it)->isDirected().value()) && - !((*it)->isWeighted().has_value() && (*it)->isWeighted().value())) { + os << *std::static_pointer_cast>(*it) + << "\n"; + } else if (((*it)->isDirected().has_value() && + (*it)->isDirected().value()) && + !((*it)->isWeighted().has_value() && + (*it)->isWeighted().value())) { os << *std::static_pointer_cast>(*it) << "\n"; - } else if (!((*it)->isDirected().has_value() && (*it)->isDirected().value()) && - ((*it)->isWeighted().has_value() && (*it)->isWeighted().value())) { - os << *std::static_pointer_cast>(*it) << "\n"; - } else if (!((*it)->isDirected().has_value() && (*it)->isDirected().value()) && - !((*it)->isWeighted().has_value() && (*it)->isWeighted().value())) { + } else if (!((*it)->isDirected().has_value() && + (*it)->isDirected().value()) && + ((*it)->isWeighted().has_value() && + (*it)->isWeighted().value())) { + os << *std::static_pointer_cast>(*it) + << "\n"; + } else if (!((*it)->isDirected().has_value() && + (*it)->isDirected().value()) && + !((*it)->isWeighted().has_value() && + (*it)->isWeighted().value())) { os << *std::static_pointer_cast>(*it) << "\n"; } else { // Should never happens diff --git a/include/CXXGraph/Partitioning/PartitionState.hpp b/include/CXXGraph/Partitioning/PartitionState.hpp old mode 100755 new mode 100644 index 39a6dc88f..c674d46e7 --- a/include/CXXGraph/Partitioning/PartitionState.hpp +++ b/include/CXXGraph/Partitioning/PartitionState.hpp @@ -23,6 +23,7 @@ #pragma once #include + #include "Record.hpp" namespace CXXGraph { @@ -32,8 +33,8 @@ using unique = std::unique_ptr; template using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; namespace Partitioning { template diff --git a/include/CXXGraph/Partitioning/PartitionStrategy.hpp b/include/CXXGraph/Partitioning/PartitionStrategy.hpp old mode 100755 new mode 100644 index a32f7e1a0..dcdf60634 --- a/include/CXXGraph/Partitioning/PartitionStrategy.hpp +++ b/include/CXXGraph/Partitioning/PartitionStrategy.hpp @@ -30,16 +30,17 @@ namespace CXXGraph { template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; namespace Partitioning { template class PartitionStrategy { public: - virtual void performStep(shared> t, shared> Sstate) = 0; + virtual void performStep(shared> t, + shared> Sstate) = 0; }; } // namespace Partitioning } // namespace CXXGraph diff --git a/include/CXXGraph/Partitioning/Partitioner.hpp b/include/CXXGraph/Partitioning/Partitioner.hpp old mode 100755 new mode 100644 index ece81055c..b289af79e --- a/include/CXXGraph/Partitioning/Partitioner.hpp +++ b/include/CXXGraph/Partitioning/Partitioner.hpp @@ -24,18 +24,18 @@ #pragma once #include +#include "CXXGraph/Edge/Edge.h" +#include "CXXGraph/Graph/Graph.h" +#include "CXXGraph/Partitioning/Utility/Globals.hpp" +#include "CXXGraph/Utility/Runnable.hpp" #include "CoordinatedPartitionState.hpp" #include "EBV.hpp" -#include "CXXGraph/Edge/Edge.h" #include "EdgeBalancedVertexCut.hpp" #include "GreedyVertexCut.hpp" #include "HDRF.hpp" #include "PartitionAlgorithm.hpp" #include "PartitionStrategy.hpp" #include "PartitionerThread.hpp" -#include "CXXGraph/Partitioning/Utility/Globals.hpp" -#include "CXXGraph/Utility/Runnable.hpp" -#include "CXXGraph/Graph/Graph.h" #include "WeightBalancedLibra.hpp" namespace CXXGraph { @@ -43,10 +43,10 @@ namespace CXXGraph { template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; namespace Partitioning { template @@ -64,7 +64,6 @@ class Partitioner { CoordinatedPartitionState performCoordinatedPartition(); public: - /** * \brief * This function partition a graph in a set of partitions @@ -76,12 +75,10 @@ class Partitioner { * @return The partiton Map of the partitioned graph */ static PartitionMap partitionGraph( - const Graph& graph, - const Partitioning::PartitionAlgorithm algorithm, + const Graph &graph, const Partitioning::PartitionAlgorithm algorithm, const unsigned int numberOfPartitions, const double param1 = 0.0, const double param2 = 0.0, const double param3 = 0.0, - const unsigned int numberOfthreads = - std::thread::hardware_concurrency()); + const unsigned int numberOfthreads = std::thread::hardware_concurrency()); }; template Partitioner::Partitioner(shared> dataset, Globals &G) @@ -122,8 +119,8 @@ Partitioner::Partitioner(shared> dataset, Globals &G) vertices_degrees[v]++; } - algorithm = make_shared>(GLOBALS, weight_sum_bound, - std::move(vertices_degrees)); + algorithm = make_shared>( + GLOBALS, weight_sum_bound, std::move(vertices_degrees)); } } @@ -165,8 +162,8 @@ Partitioner::Partitioner(const Partitioner &other) { vertices_degrees[v]++; } - algorithm = make_shared>(GLOBALS, weight_sum_bound, - std::move(vertices_degrees)); + algorithm = make_shared>( + GLOBALS, weight_sum_bound, std::move(vertices_degrees)); } } @@ -184,13 +181,12 @@ CoordinatedPartitionState Partitioner::startCoordinated() { int iStart = t * subSize; int iEnd = std::min((t + 1) * subSize, (int)n); if (iEnd >= iStart) { - list_vector[t] = - std::vector>>(std::next(dataset->begin(), iStart), - std::next(dataset->begin(), iEnd)); - myRunnable[t].reset( - new PartitionerThread(list_vector[t], - make_shared>(state), - algorithm)); + list_vector[t] = std::vector>>( + std::next(dataset->begin(), iStart), + std::next(dataset->begin(), iEnd)); + myRunnable[t].reset(new PartitionerThread( + list_vector[t], make_shared>(state), + algorithm)); myThreads[t] = std::thread(&Runnable::run, myRunnable[t].get()); } } @@ -219,11 +215,10 @@ CoordinatedPartitionState Partitioner::performCoordinatedPartition() { template PartitionMap Partitioner::partitionGraph( - const Graph& graph, - const Partitioning::PartitionAlgorithm algorithm, + const Graph &graph, const Partitioning::PartitionAlgorithm algorithm, const unsigned int numberOfPartitions, const double param1, const double param2, const double param3, - const unsigned int numberOfThreads){ + const unsigned int numberOfThreads) { PartitionMap partitionMap; Partitioning::Globals globals(numberOfPartitions, algorithm, param1, param2, param3, numberOfThreads); @@ -237,7 +232,6 @@ PartitionMap Partitioner::partitionGraph( return partitionMap; } - } // namespace Partitioning } // namespace CXXGraph diff --git a/include/CXXGraph/Partitioning/PartitionerThread.hpp b/include/CXXGraph/Partitioning/PartitionerThread.hpp old mode 100755 new mode 100644 index 32193b65a..f2a740648 --- a/include/CXXGraph/Partitioning/PartitionerThread.hpp +++ b/include/CXXGraph/Partitioning/PartitionerThread.hpp @@ -26,9 +26,9 @@ #include #include "CXXGraph/Edge/Edge.h" +#include "CXXGraph/Utility/Runnable.hpp" #include "PartitionState.hpp" #include "PartitionStrategy.hpp" -#include "CXXGraph/Utility/Runnable.hpp" namespace CXXGraph { namespace Partitioning { @@ -42,7 +42,7 @@ class PartitionerThread : public Runnable { public: PartitionerThread(std::vector>> &list, shared> state, - shared> algorithm); + shared> algorithm); ~PartitionerThread(); void run() override; @@ -50,9 +50,9 @@ class PartitionerThread : public Runnable { std::list id_partitions; }; template -PartitionerThread::PartitionerThread(std::vector>> &list, - shared> state, - shared> algorithm) { +PartitionerThread::PartitionerThread( + std::vector>> &list, shared> state, + shared> algorithm) { this->list = list; this->state = state; this->algorithm = algorithm; diff --git a/include/CXXGraph/Partitioning/WeightBalancedLibra.hpp b/include/CXXGraph/Partitioning/WeightBalancedLibra.hpp old mode 100755 new mode 100644 index 117cc66e9..00698204b --- a/include/CXXGraph/Partitioning/WeightBalancedLibra.hpp +++ b/include/CXXGraph/Partitioning/WeightBalancedLibra.hpp @@ -25,8 +25,8 @@ #include #include "CXXGraph/Edge/Edge.h" -#include "PartitionStrategy.hpp" #include "CXXGraph/Partitioning/Utility/Globals.hpp" +#include "PartitionStrategy.hpp" namespace CXXGraph { namespace Partitioning { @@ -50,7 +50,8 @@ class WeightBalancedLibra : public PartitionStrategy { std::unordered_map &&_vertices_degrees); ~WeightBalancedLibra(); - void performStep(shared> e, shared> Sstate) override; + void performStep(shared> e, + shared> Sstate) override; }; template WeightBalancedLibra::WeightBalancedLibra( diff --git a/include/CXXGraph/Utility/PointerHash.hpp b/include/CXXGraph/Utility/PointerHash.hpp old mode 100755 new mode 100644 index 5027255ec..f63d3112c --- a/include/CXXGraph/Utility/PointerHash.hpp +++ b/include/CXXGraph/Utility/PointerHash.hpp @@ -37,21 +37,21 @@ namespace CXXGraph { template using shared = std::shared_ptr; -// Redefine the hash functions and equality operators for shared pointers of nodes and edges +// Redefine the hash functions and equality operators for shared pointers of +// nodes and edges template struct nodeHash { size_t operator()(const shared>& node) const { return node->getId(); } - size_t operator()(const shared>& node) const { - return node->getId(); - } + size_t operator()(const shared>& node) const { return node->getId(); } }; template struct edgeHash { size_t operator()(const shared>& edge) const { - return (edge->getNodePair().first->getId()) ^ (edge->getNodePair().second->getId()); + return (edge->getNodePair().first->getId()) ^ + (edge->getNodePair().second->getId()); } }; diff --git a/include/CXXGraph/Utility/Reader.hpp b/include/CXXGraph/Utility/Reader.hpp old mode 100755 new mode 100644 index 4c8b64c69..729951c18 --- a/include/CXXGraph/Utility/Reader.hpp +++ b/include/CXXGraph/Utility/Reader.hpp @@ -23,7 +23,7 @@ #pragma once // This is to make sure that this header is only included once namespace CXXGraph { -//Foward declaration +// Foward declaration template class Graph; /*! diff --git a/include/CXXGraph/Utility/Typedef.hpp b/include/CXXGraph/Utility/Typedef.hpp old mode 100755 new mode 100644 index f0ce56d45..bc8b27755 --- a/include/CXXGraph/Utility/Typedef.hpp +++ b/include/CXXGraph/Utility/Typedef.hpp @@ -36,7 +36,6 @@ namespace CXXGraph { template using shared = std::shared_ptr; - template class Node; @@ -193,7 +192,7 @@ struct SCCResult_struct { std::string errorMessage = ""; // message of error int noOfComponents = 0; std::unordered_map sccMap; - //Components stronglyConnectedComps; + // Components stronglyConnectedComps; }; template using SCCResult = SCCResult_struct; @@ -220,9 +219,9 @@ struct TarjanResult_struct { std::vector> cutVertices; // a vector that stores cut vertices // (valid only is a graph is undirected and // flag TARJAN_FIND_CUTV is set) - std::vector> bridges; // a vector that stores bridges - // (valid only is a graph is undirected and - // flag TRAJAN_FIND_BRIDGES is set) + std::vector> bridges; // a vector that stores bridges + // (valid only is a graph is undirected and + // flag TRAJAN_FIND_BRIDGES is set) }; template using TarjanResult = TarjanResult_struct; @@ -249,10 +248,8 @@ using AdjacencyMatrix = std::unordered_map< nodeHash>; template -using DegreeMatrix = std::unordered_map< - shared>, - std::vector, - nodeHash>; +using DegreeMatrix = + std::unordered_map>, std::vector, nodeHash>; template using LaplacianMatrix = std::unordered_map< @@ -261,10 +258,10 @@ using LaplacianMatrix = std::unordered_map< nodeHash>; template -using TransitionMatrix = std::unordered_map< - shared>, - std::vector>, double>>, - nodeHash>; +using TransitionMatrix = + std::unordered_map>, + std::vector>, double>>, + nodeHash>; template using PartitionMap = diff --git a/include/CXXGraph/Utility/id_t.hpp b/include/CXXGraph/Utility/id_t.hpp index f997356dd..504acd695 100644 --- a/include/CXXGraph/Utility/id_t.hpp +++ b/include/CXXGraph/Utility/id_t.hpp @@ -6,11 +6,12 @@ namespace CXXGraph { #ifdef CXXGRAPH_ID_TYPE - // Throw compiler error if the type is signed - static_assert(IS_UNSIGNED(CXXGRAPH_ID_TYPE), "CXXGRAPH_ID_TYPE must be unsigned"); +// Throw compiler error if the type is signed +static_assert(IS_UNSIGNED(CXXGRAPH_ID_TYPE), + "CXXGRAPH_ID_TYPE must be unsigned"); - typedef CXXGRAPH_ID_TYPE id_t; +typedef CXXGRAPH_ID_TYPE id_t; #else - typedef size_t id_t; +typedef size_t id_t; #endif -} +} // namespace CXXGraph diff --git a/test/BFSTest.cpp b/test/BFSTest.cpp index c23349da3..27a71b035 100644 --- a/test/BFSTest.cpp +++ b/test/BFSTest.cpp @@ -8,10 +8,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(BFSTest, test_1) { CXXGraph::Node node1("1", 1); @@ -310,14 +310,15 @@ TEST(BFSTest, test_13) { int randomNumber2 = (distribution(rand) % MaxValue); if (randomNumber1 != randomNumber2) { shared> newEdge = - make_shared>(index, *(nodes.at(randomNumber1)), - *(nodes.at(randomNumber2))); + make_shared>( + index, *(nodes.at(randomNumber1)), *(nodes.at(randomNumber2))); edgeSet.insert(newEdge); } } for (int i = 1; i < nodes.size(); i += 2) { - shared> newEdge = make_shared>( - edges_size + i + 1, *(nodes.at(0)), *(nodes.at(i))); + shared> newEdge = + make_shared>( + edges_size + i + 1, *(nodes.at(0)), *(nodes.at(i))); edgeSet.insert(newEdge); } CXXGraph::Graph graph(edgeSet); diff --git a/test/BellmanFordTest.cpp b/test/BellmanFordTest.cpp index b336d9721..60be0e8d2 100644 --- a/test/BellmanFordTest.cpp +++ b/test/BellmanFordTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // check if algorithm works using a complicated test case TEST(BellmanFordTest, test_1) { diff --git a/test/BestFirstSearchTest.cpp b/test/BestFirstSearchTest.cpp index 6d560020b..20fe4a0bb 100644 --- a/test/BestFirstSearchTest.cpp +++ b/test/BestFirstSearchTest.cpp @@ -8,10 +8,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(BestFirstSearchTest, source_node_missing) { CXXGraph::Node node1("1", 1); diff --git a/test/BoruvkaTest.cpp b/test/BoruvkaTest.cpp index 675017b21..20d91c4ff 100644 --- a/test/BoruvkaTest.cpp +++ b/test/BoruvkaTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // minimum spanning tree can differ so instead of checking // the exact order of elements, we can check some properties diff --git a/test/ConnectivityTest.cpp b/test/ConnectivityTest.cpp index 3685c9a34..90c726f08 100644 --- a/test/ConnectivityTest.cpp +++ b/test/ConnectivityTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(ConnectivityTest, test_1) { CXXGraph::Node node0("0", 0); diff --git a/test/CycleCheckTest.cpp b/test/CycleCheckTest.cpp index 3220e0f6f..6216b52d2 100644 --- a/test/CycleCheckTest.cpp +++ b/test/CycleCheckTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(CycleCheckTest, test_1) { CXXGraph::Node node1("1", 1); diff --git a/test/DOTTest.cpp b/test/DOTTest.cpp index 93d67d54d..9b5144a05 100644 --- a/test/DOTTest.cpp +++ b/test/DOTTest.cpp @@ -7,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(DOTTest, WriteToDotDirectedWeighted) { // Generate a simple test graph with few nodes and edges diff --git a/test/DialTest.cpp b/test/DialTest.cpp index 92fa2f76d..782c21ca7 100644 --- a/test/DialTest.cpp +++ b/test/DialTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(DialTest, test_1) { CXXGraph::Node node1("1", 1); diff --git a/test/DijkstraTest.cpp b/test/DijkstraTest.cpp index d30c13bec..4588b8b8d 100644 --- a/test/DijkstraTest.cpp +++ b/test/DijkstraTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(DijkstraTest, correct_example_1) { CXXGraph::Node node1("1", 1); @@ -33,13 +34,13 @@ TEST(DijkstraTest, correct_example_1) { expected.push_back("1"); expected.push_back("2"); expected.push_back("3"); - int index=0; + int index = 0; ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 2); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } } @@ -65,13 +66,13 @@ TEST(DijkstraTest, correct_example_2) { std::vector expected; expected.push_back("1"); expected.push_back("3"); - int index=0; + int index = 0; ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 6); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } } @@ -107,55 +108,55 @@ TEST(DijkstraTest, correct_example_3) { expected.push_back("A"); expected.push_back("B"); expected.push_back("E"); - int index=0; + int index = 0; CXXGraph::Graph graph(edgeSet); CXXGraph::DijkstraResult res = graph.dijkstra(nodeC, nodeE); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 5); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } expected.clear(); expected.push_back("C"); expected.push_back("A"); - index=0; + index = 0; res = graph.dijkstra(nodeC, nodeA); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 1); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } expected.clear(); expected.push_back("C"); expected.push_back("A"); expected.push_back("B"); - index=0; + index = 0; res = graph.dijkstra(nodeC, nodeB); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 4); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } expected.clear(); expected.push_back("C"); expected.push_back("D"); - index=0; + index = 0; res = graph.dijkstra(nodeC, nodeD); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 2); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } } @@ -195,43 +196,43 @@ TEST(DijkstraTest, correct_example_4) { std::vector expected; expected.push_back("0"); expected.push_back("1"); - int index=0; + int index = 0; CXXGraph::Graph graph(edgeSet); CXXGraph::DijkstraResult res = graph.dijkstra(node0, node1); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 2); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } expected.clear(); expected.push_back("0"); expected.push_back("2"); - index=0; - + index = 0; + res = graph.dijkstra(node0, node2); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 6); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } expected.clear(); expected.push_back("0"); expected.push_back("1"); expected.push_back("3"); - index=0; + index = 0; res = graph.dijkstra(node0, node3); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 7); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } expected.clear(); @@ -239,14 +240,14 @@ TEST(DijkstraTest, correct_example_4) { expected.push_back("1"); expected.push_back("3"); expected.push_back("4"); - index=0; + index = 0; res = graph.dijkstra(node0, node4); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 17); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } expected.clear(); @@ -254,14 +255,14 @@ TEST(DijkstraTest, correct_example_4) { expected.push_back("1"); expected.push_back("3"); expected.push_back("5"); - index=0; + index = 0; res = graph.dijkstra(node0, node5); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 22); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } expected.clear(); @@ -270,14 +271,14 @@ TEST(DijkstraTest, correct_example_4) { expected.push_back("3"); expected.push_back("4"); expected.push_back("6"); - index=0; + index = 0; res = graph.dijkstra(node0, node6); ASSERT_TRUE(res.success); ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 19); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } } @@ -313,7 +314,7 @@ TEST(DijkstraTest, correct_example_5) { edgeSet.insert(make_shared>(edge9)); std::vector expected; - int index=0; + int index = 0; expected.push_back("1"); expected.push_back("3"); expected.push_back("6"); @@ -324,8 +325,8 @@ TEST(DijkstraTest, correct_example_5) { ASSERT_EQ(res.errorMessage, ""); ASSERT_EQ(res.result, 20); ASSERT_EQ(res.path.size(), expected.size()); - for(auto elem:res.path){ - ASSERT_EQ(elem,expected[index]); + for (auto elem : res.path) { + ASSERT_EQ(elem, expected[index]); index++; } } diff --git a/test/DirectedEdgeTest.cpp b/test/DirectedEdgeTest.cpp index 1c8f6338d..d0b1d5bdc 100644 --- a/test/DirectedEdgeTest.cpp +++ b/test/DirectedEdgeTest.cpp @@ -5,10 +5,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(DirectedEdgeTest, Constructor_1) { CXXGraph::Node node1("1", 1); @@ -74,8 +74,8 @@ TEST(DirectedEdgeTest, Bool_data) { // Second constructor CXXGraph::Node node3("3", true); CXXGraph::Node node4("4", false); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::DirectedEdge edge2(2, pairNode); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); @@ -97,8 +97,8 @@ TEST(DirectedEdgeTest, String_data) { // Second constructor CXXGraph::Node node3("3", "On"); CXXGraph::Node node4("4", "Off"); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::DirectedEdge edge2(2, pairNode); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); diff --git a/test/DirectedWeightedEdgeTest.cpp b/test/DirectedWeightedEdgeTest.cpp index da1bb5b5c..deb6b786a 100644 --- a/test/DirectedWeightedEdgeTest.cpp +++ b/test/DirectedWeightedEdgeTest.cpp @@ -5,10 +5,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(DirectedWeightedEdgeTest, Constructor_1) { CXXGraph::Node node1("1", 1); @@ -107,8 +107,8 @@ TEST(DirectedWeightedEdgeTest, Bool_data) { // Second constructor CXXGraph::Node node3("3", true); CXXGraph::Node node4("4", false); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::DirectedWeightedEdge edge2(2, pairNode, 2); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); @@ -130,8 +130,8 @@ TEST(DirectedWeightedEdgeTest, String_data) { // Second constructor CXXGraph::Node node3("3", "On"); CXXGraph::Node node4("4", "Off"); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::DirectedWeightedEdge edge2(2, pairNode, 6); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); diff --git a/test/EdgeTest.cpp b/test/EdgeTest.cpp index 9b0d4e6a8..1efd82a0e 100644 --- a/test/EdgeTest.cpp +++ b/test/EdgeTest.cpp @@ -5,10 +5,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(EdgeTest, Constructor_1) { CXXGraph::Node node1("1", 1); @@ -48,8 +48,8 @@ TEST(EdgeTest, Bool_data) { // Second constructor CXXGraph::Node node3("3", true); CXXGraph::Node node4("4", false); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::Edge edge2(2, pairNode); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); @@ -67,8 +67,8 @@ TEST(EdgeTest, String_data) { // Second constructor CXXGraph::Node node3("3", "On"); CXXGraph::Node node4("4", "Off"); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::Edge edge2(2, pairNode); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); diff --git a/test/EulerPathTest.cpp b/test/EulerPathTest.cpp index 87da7f6c8..b57a62b5f 100644 --- a/test/EulerPathTest.cpp +++ b/test/EulerPathTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // example taken from // https://www.geeksforgeeks.org/hierholzers-algorithm-directed-graph/ diff --git a/test/FWTest.cpp b/test/FWTest.cpp index 7e37c1705..13580d59a 100644 --- a/test/FWTest.cpp +++ b/test/FWTest.cpp @@ -8,10 +8,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm#Example TEST(FWTest, test_1) { diff --git a/test/FordFulkersonTest.cpp b/test/FordFulkersonTest.cpp index 47b253cd0..a3a958314 100644 --- a/test/FordFulkersonTest.cpp +++ b/test/FordFulkersonTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(FordFulkersonTest, test_1) { CXXGraph::Node node0("0", 0); diff --git a/test/GraphSlicingTest.cpp b/test/GraphSlicingTest.cpp index 05c78d50e..2c4917ab5 100644 --- a/test/GraphSlicingTest.cpp +++ b/test/GraphSlicingTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // DirectedEdge TEST(GraphSlicingTest, test_1) { diff --git a/test/KahnTest.cpp b/test/KahnTest.cpp index ad8baa28d..6e84150f5 100644 --- a/test/KahnTest.cpp +++ b/test/KahnTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(KahnTest, error_cyclic_graph) { CXXGraph::Node node1("1", 1); diff --git a/test/KosarajuTest.cpp b/test/KosarajuTest.cpp index a3c129719..07a550a4f 100644 --- a/test/KosarajuTest.cpp +++ b/test/KosarajuTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // helper function to compare strongly connected components (SCC) as computed // by the algorithm with expected (correct) SCC @@ -17,9 +18,9 @@ void compareComponents(CXXGraph::SCCResult result, CXXGraph::Components& comp2) { ASSERT_EQ(result.noOfComponents, comp2.size()); - for(int i=0;i + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // minimum spanning tree can differ so instead of checking // the exact order of elements, we can check some properties diff --git a/test/MTXTest.cpp b/test/MTXTest.cpp index a92303260..3590f6416 100644 --- a/test/MTXTest.cpp +++ b/test/MTXTest.cpp @@ -7,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(MTXTest, WriteToMtxDirectedWeighted) { // Generate a simple test graph with few nodes and edges @@ -85,9 +85,10 @@ TEST(MTXTest, ReadFromMtxDirectedWeighted) { ASSERT_EQ(graph.getEdge(0).value()->isDirected(), false); // Check that it's weighted and the value of the weight ASSERT_EQ(graph.getEdge(0).value()->isWeighted(), true); - ASSERT_EQ(dynamic_cast(graph.getEdge(0).value().get()) - ->getWeight(), - 1.); + ASSERT_EQ( + dynamic_cast(graph.getEdge(0).value().get()) + ->getWeight(), + 1.); // Check the last edge ASSERT_EQ(graph.getEdge(7).value()->getNodePair().first->getUserId(), "5"); @@ -96,9 +97,10 @@ TEST(MTXTest, ReadFromMtxDirectedWeighted) { ASSERT_EQ(graph.getEdge(7).value()->isDirected(), false); // Check that it's weighted and the value of the weight ASSERT_EQ(graph.getEdge(7).value()->isWeighted(), true); - ASSERT_EQ(dynamic_cast(graph.getEdge(7).value().get()) - ->getWeight(), - 12.); + ASSERT_EQ( + dynamic_cast(graph.getEdge(7).value().get()) + ->getWeight(), + 12.); // Check an edge in the middle ASSERT_EQ(graph.getEdge(3).value()->getNodePair().first->getUserId(), "1"); @@ -107,9 +109,10 @@ TEST(MTXTest, ReadFromMtxDirectedWeighted) { ASSERT_EQ(graph.getEdge(3).value()->isDirected(), true); // Check that it's weighted and the value of the weight ASSERT_EQ(graph.getEdge(3).value()->isWeighted(), true); - ASSERT_EQ(dynamic_cast(graph.getEdge(3).value().get()) - ->getWeight(), - 6.); + ASSERT_EQ( + dynamic_cast(graph.getEdge(3).value().get()) + ->getWeight(), + 6.); } TEST(MTXTest, ReadFromMtxUndirectedWeighted) { @@ -127,9 +130,10 @@ TEST(MTXTest, ReadFromMtxUndirectedWeighted) { ASSERT_EQ(graph.getEdge(0).value()->isDirected(), false); // Check that it's weighted and the value of the weight ASSERT_EQ(graph.getEdge(0).value()->isWeighted(), true); - ASSERT_EQ(dynamic_cast(graph.getEdge(0).value().get()) - ->getWeight(), - 1.); + ASSERT_EQ( + dynamic_cast(graph.getEdge(0).value().get()) + ->getWeight(), + 1.); // Check the last edge ASSERT_EQ(graph.getEdge(7).value()->getNodePair().first->getUserId(), "5"); @@ -138,9 +142,10 @@ TEST(MTXTest, ReadFromMtxUndirectedWeighted) { ASSERT_EQ(graph.getEdge(7).value()->isDirected(), false); // Check that it's weighted and the value of the weight ASSERT_EQ(graph.getEdge(7).value()->isWeighted(), true); - ASSERT_EQ(dynamic_cast(graph.getEdge(7).value().get()) - ->getWeight(), - 12.); + ASSERT_EQ( + dynamic_cast(graph.getEdge(7).value().get()) + ->getWeight(), + 12.); // Check an edge in the middle ASSERT_EQ(graph.getEdge(3).value()->getNodePair().first->getUserId(), "1"); @@ -149,7 +154,8 @@ TEST(MTXTest, ReadFromMtxUndirectedWeighted) { ASSERT_EQ(graph.getEdge(3).value()->isDirected(), false); // Check that it's weighted and the value of the weight ASSERT_EQ(graph.getEdge(3).value()->isWeighted(), true); - ASSERT_EQ(dynamic_cast(graph.getEdge(3).value().get()) - ->getWeight(), - 6.); + ASSERT_EQ( + dynamic_cast(graph.getEdge(3).value().get()) + ->getWeight(), + 6.); } diff --git a/test/NodeTest.cpp b/test/NodeTest.cpp index a14ab7ba6..e2e400f88 100644 --- a/test/NodeTest.cpp +++ b/test/NodeTest.cpp @@ -5,10 +5,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // Struct for testing Node as a template of different items struct testStruct { diff --git a/test/PrimTest.cpp b/test/PrimTest.cpp index fa764e8b9..0bdd7f317 100644 --- a/test/PrimTest.cpp +++ b/test/PrimTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // minimum spanning tree can differ so instead of checking // the exact order of elements, we can check some properties diff --git a/test/RWOutputTest.cpp b/test/RWOutputTest.cpp index ca589087e..ee492d325 100644 --- a/test/RWOutputTest.cpp +++ b/test/RWOutputTest.cpp @@ -8,10 +8,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; inline bool exists_test(const std::string &name) { struct stat buffer; @@ -390,9 +390,9 @@ TEST(RWOutputTest, test_10) { readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 5); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 5); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -415,9 +415,9 @@ TEST(RWOutputTest, test_10) { !readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 6); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 6); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -773,9 +773,9 @@ TEST(RWOutputTest, test_20) { readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 5); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 5); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -798,9 +798,9 @@ TEST(RWOutputTest, test_20) { !readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 6); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 6); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -886,9 +886,9 @@ TEST(RWOutputTest, test_22) { readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 5); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 5); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -911,9 +911,9 @@ TEST(RWOutputTest, test_22) { !readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 6); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 6); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -1026,9 +1026,9 @@ TEST(RWOutputTest, test_25) { readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 5); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 5); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -1051,9 +1051,9 @@ TEST(RWOutputTest, test_25) { !readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 6); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 6); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -1193,9 +1193,9 @@ TEST(RWOutputTest, test_29) { readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 5); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 5); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); @@ -1218,9 +1218,9 @@ TEST(RWOutputTest, test_29) { !readEdgeIt->isDirected().value()); ASSERT_TRUE(readEdgeIt->isWeighted().has_value() && readEdgeIt->isWeighted().value()); - ASSERT_EQ( - (dynamic_cast(readEdgeIt.get()))->getWeight(), - 6); + ASSERT_EQ((dynamic_cast(readEdgeIt.get())) + ->getWeight(), + 6); ASSERT_EQ(readEdgeIt->getNodePair().first->getUserId(), node1.getUserId()); ASSERT_EQ(readEdgeIt->getNodePair().first->getData(), node1.getData()); diff --git a/test/TarjanTest.cpp b/test/TarjanTest.cpp index 211423208..2405609f4 100644 --- a/test/TarjanTest.cpp +++ b/test/TarjanTest.cpp @@ -116,15 +116,13 @@ TEST(TarjanTest, test_3) { for (int i = 1; i <= 18; ++i) { nodes.emplace_back(std::to_string(i), i); }; - std::vector> pairs{ - {1, 2}, {2, 3}, {3, 4}, {2, 4}, {2, 5}, {2, 6}, - {5, 6}, {5, 7}, {6, 7}, {7, 8}, {7, 11}, {8, 11}, - {8, 9}, {9, 11}, {8, 12}, {8, 14}, {8, 15}, - {12, 13}, {14, 13}, {15, 13}, {9, 10}, {11, 10}, - {10, 16}, {10, 17}, {10, 18}, {17, 18} - }; + std::vector> pairs{ + {1, 2}, {2, 3}, {3, 4}, {2, 4}, {2, 5}, {2, 6}, {5, 6}, + {5, 7}, {6, 7}, {7, 8}, {7, 11}, {8, 11}, {8, 9}, {9, 11}, + {8, 12}, {8, 14}, {8, 15}, {12, 13}, {14, 13}, {15, 13}, {9, 10}, + {11, 10}, {10, 16}, {10, 17}, {10, 18}, {17, 18}}; std::vector> edges; - for (const auto& [id1, id2] : pairs) { + for (const auto &[id1, id2] : pairs) { edges.emplace_back(edges.size() + 1, nodes[id1], nodes[id2], 1); } CXXGraph::T_EdgeSet edgeSet; @@ -137,9 +135,10 @@ TEST(TarjanTest, test_3) { std::vector expectRes{2, 7, 8, 10}; ASSERT_EQ(res.cutVertices.size(), expectRes.size()); - std::sort(res.cutVertices.begin(), res.cutVertices.end(), [&](const auto &node1, const auto &node2) { - return node1.getData() < node2.getData(); - }); + std::sort(res.cutVertices.begin(), res.cutVertices.end(), + [&](const auto &node1, const auto &node2) { + return node1.getData() < node2.getData(); + }); for (int i = 0; i < expectRes.size(); ++i) { ASSERT_EQ(res.cutVertices[i], nodes[expectRes[i]]); } @@ -158,15 +157,13 @@ TEST(TarjanTest, test_4) { for (int i = 1; i <= 18; ++i) { nodes.emplace_back(std::to_string(i), i); }; - std::vector> pairs{ - {1, 2}, {2, 3}, {3, 4}, {2, 4}, {2, 5}, {2, 6}, - {5, 6}, {5, 7}, {6, 7}, {7, 8}, {7, 11}, {8, 11}, - {8, 9}, {9, 11}, {8, 12}, {8, 14}, {8, 15}, - {12, 13}, {14, 13}, {15, 13}, {9, 10}, {11, 10}, - {10, 16}, {10, 17}, {10, 18}, {17, 18} - }; + std::vector> pairs{ + {1, 2}, {2, 3}, {3, 4}, {2, 4}, {2, 5}, {2, 6}, {5, 6}, + {5, 7}, {6, 7}, {7, 8}, {7, 11}, {8, 11}, {8, 9}, {9, 11}, + {8, 12}, {8, 14}, {8, 15}, {12, 13}, {14, 13}, {15, 13}, {9, 10}, + {11, 10}, {10, 16}, {10, 17}, {10, 18}, {17, 18}}; std::vector> edges; - for (const auto& [id1, id2] : pairs) { + for (const auto &[id1, id2] : pairs) { edges.emplace_back(edges.size() + 1, nodes[id1], nodes[id2], 1); } CXXGraph::T_EdgeSet edgeSet; @@ -178,13 +175,13 @@ TEST(TarjanTest, test_4) { ASSERT_EQ(res.success, true); std::vector>> expectRes{ - {nodes[1], nodes[2]}, {nodes[2], nodes[3], nodes[4]}, - {nodes[2], nodes[5], nodes[6], nodes[7]}, + {nodes[1], nodes[2]}, + {nodes[2], nodes[3], nodes[4]}, + {nodes[2], nodes[5], nodes[6], nodes[7]}, {nodes[7], nodes[8], nodes[9], nodes[10], nodes[11]}, {nodes[8], nodes[12], nodes[13], nodes[14], nodes[15]}, {nodes[10], nodes[16]}, - {nodes[10], nodes[17], nodes[18]} - }; + {nodes[10], nodes[17], nodes[18]}}; ASSERT_EQ(res.verticeBiconnectedComps.size(), expectRes.size()); // sort nodes in a vbcc by node id @@ -197,10 +194,11 @@ TEST(TarjanTest, test_4) { std::sort(res.verticeBiconnectedComps.begin(), res.verticeBiconnectedComps.end(), [&](const auto &scc1, const auto &scc2) { - if ((scc1.size() == 0) || (scc2.size() == 0) || (scc1[0].getData() == scc2[0].getData())) { + if ((scc1.size() == 0) || (scc2.size() == 0) || + (scc1[0].getData() == scc2[0].getData())) { return scc1.size() < scc2.size(); } - return scc1[0].getData() < scc2[0].getData(); + return scc1[0].getData() < scc2[0].getData(); }); for (int i = 0; i < res.verticeBiconnectedComps.size(); ++i) { ASSERT_EQ(res.verticeBiconnectedComps[i].size(), expectRes[i].size()); @@ -215,22 +213,20 @@ TEST(TarjanTest, test_4) { ASSERT_EQ(res.cutVertices.size(), 0); } - TEST(TarjanTest, test_5) { - // the undirected graph used in this case is a bridge tree from a tutorial on codeforce - // https://codeforces.com/blog/entry/99259 + // the undirected graph used in this case is a bridge tree from a tutorial on + // codeforce https://codeforces.com/blog/entry/99259 std::vector> nodes; nodes.emplace_back("0", 0); for (int i = 1; i <= 12; ++i) { nodes.emplace_back(std::to_string(i), i); }; - std::vector> pairs{ - {1, 2}, {2, 3}, {1, 3}, {3, 4}, {3, 9}, - {4, 5}, {5, 6}, {4, 7}, {6, 7}, {6, 8}, - {7, 8}, {9, 10}, {9, 11}, {10, 12}, {11, 12}, + std::vector> pairs{ + {1, 2}, {2, 3}, {1, 3}, {3, 4}, {3, 9}, {4, 5}, {5, 6}, {4, 7}, + {6, 7}, {6, 8}, {7, 8}, {9, 10}, {9, 11}, {10, 12}, {11, 12}, }; std::vector> edges; - for (const auto& [id1, id2] : pairs) { + for (const auto &[id1, id2] : pairs) { edges.emplace_back(edges.size() + 1, nodes[id1], nodes[id2], 1); } CXXGraph::T_EdgeSet edgeSet; @@ -243,9 +239,10 @@ TEST(TarjanTest, test_5) { std::vector expectRes{3, 4}; ASSERT_EQ(res.bridges.size(), expectRes.size()); - std::sort(res.bridges.begin(), res.bridges.end(), [&](const auto &edge1, const auto &edge2) { - return edge1.getId() < edge2.getId(); - }); + std::sort(res.bridges.begin(), res.bridges.end(), + [&](const auto &edge1, const auto &edge2) { + return edge1.getId() < edge2.getId(); + }); for (int i = 0; i < expectRes.size(); ++i) { ASSERT_EQ(res.bridges[i], edges[expectRes[i]]); } @@ -257,20 +254,19 @@ TEST(TarjanTest, test_5) { } TEST(TarjanTest, test_6) { - // the undirected graph used in this case is a bridge tree from a tutorial on codeforce - // https://codeforces.com/blog/entry/99259 + // the undirected graph used in this case is a bridge tree from a tutorial on + // codeforce https://codeforces.com/blog/entry/99259 std::vector> nodes; nodes.emplace_back("0", 0); for (int i = 1; i <= 12; ++i) { nodes.emplace_back(std::to_string(i), i); }; - std::vector> pairs{ - {1, 2}, {2, 3}, {1, 3}, {3, 4}, {3, 9}, - {4, 5}, {5, 6}, {4, 7}, {6, 7}, {6, 8}, - {7, 8}, {9, 10}, {9, 11}, {10, 12}, {11, 12}, + std::vector> pairs{ + {1, 2}, {2, 3}, {1, 3}, {3, 4}, {3, 9}, {4, 5}, {5, 6}, {4, 7}, + {6, 7}, {6, 8}, {7, 8}, {9, 10}, {9, 11}, {10, 12}, {11, 12}, }; std::vector> edges; - for (const auto& [id1, id2] : pairs) { + for (const auto &[id1, id2] : pairs) { edges.emplace_back(edges.size() + 1, nodes[id1], nodes[id2], 1); } CXXGraph::T_EdgeSet edgeSet; @@ -282,10 +278,9 @@ TEST(TarjanTest, test_6) { ASSERT_EQ(res.success, true); std::vector>> expectRes{ - {nodes[1], nodes[2], nodes[3]}, - {nodes[4], nodes[5], nodes[6], nodes[7], nodes[8]}, - {nodes[9], nodes[10], nodes[11], nodes[12]} - }; + {nodes[1], nodes[2], nodes[3]}, + {nodes[4], nodes[5], nodes[6], nodes[7], nodes[8]}, + {nodes[9], nodes[10], nodes[11], nodes[12]}}; ASSERT_EQ(res.edgeBiconnectedComps.size(), expectRes.size()); // sort nodes in a vbcc by node id @@ -295,13 +290,13 @@ TEST(TarjanTest, test_6) { }); } // sort vbccs by first node and size - std::sort(res.edgeBiconnectedComps.begin(), - res.edgeBiconnectedComps.end(), + std::sort(res.edgeBiconnectedComps.begin(), res.edgeBiconnectedComps.end(), [&](const auto &scc1, const auto &scc2) { - if ((scc1.size() == 0) || (scc2.size() == 0) || (scc1[0].getData() == scc2[0].getData())) { + if ((scc1.size() == 0) || (scc2.size() == 0) || + (scc1[0].getData() == scc2[0].getData())) { return scc1.size() < scc2.size(); } - return scc1[0].getData() < scc2[0].getData(); + return scc1[0].getData() < scc2[0].getData(); }); for (int i = 0; i < res.edgeBiconnectedComps.size(); ++i) { ASSERT_EQ(res.edgeBiconnectedComps[i].size(), expectRes[i].size()); @@ -324,15 +319,13 @@ TEST(TarjanTest, test_7) { for (int i = 1; i <= 18; ++i) { nodes.emplace_back(std::to_string(i), i); }; - std::vector> pairs{ - {1, 2}, {2, 3}, {3, 4}, {2, 4}, {2, 5}, {2, 6}, - {5, 6}, {5, 7}, {6, 7}, {7, 8}, {7, 11}, {8, 11}, - {8, 9}, {9, 11}, {8, 12}, {8, 14}, {8, 15}, - {12, 13}, {14, 13}, {15, 13}, {9, 10}, {11, 10}, - {10, 16}, {10, 17}, {10, 18}, {17, 18} - }; + std::vector> pairs{ + {1, 2}, {2, 3}, {3, 4}, {2, 4}, {2, 5}, {2, 6}, {5, 6}, + {5, 7}, {6, 7}, {7, 8}, {7, 11}, {8, 11}, {8, 9}, {9, 11}, + {8, 12}, {8, 14}, {8, 15}, {12, 13}, {14, 13}, {15, 13}, {9, 10}, + {11, 10}, {10, 16}, {10, 17}, {10, 18}, {17, 18}}; std::vector> edges; - for (const auto& [id1, id2] : pairs) { + for (const auto &[id1, id2] : pairs) { edges.emplace_back(edges.size() + 1, nodes[id1], nodes[id2], 1); } CXXGraph::T_EdgeSet edgeSet; @@ -341,11 +334,17 @@ TEST(TarjanTest, test_7) { } CXXGraph::Graph graph(edgeSet); - CXXGraph::TarjanResult cutvRes = graph.tarjan(CXXGraph::TARJAN_FIND_CUTV); - CXXGraph::TarjanResult bridgeRes = graph.tarjan(CXXGraph::TARJAN_FIND_BRIDGE); - CXXGraph::TarjanResult vbccRes = graph.tarjan(CXXGraph::TARJAN_FIND_VBCC); - CXXGraph::TarjanResult ebccRes = graph.tarjan(CXXGraph::TARJAN_FIND_EBCC); - CXXGraph::TarjanResult res = graph.tarjan(CXXGraph::TARJAN_FIND_CUTV | CXXGraph::TARJAN_FIND_BRIDGE | CXXGraph::TARJAN_FIND_EBCC | CXXGraph::TARJAN_FIND_VBCC); + CXXGraph::TarjanResult cutvRes = + graph.tarjan(CXXGraph::TARJAN_FIND_CUTV); + CXXGraph::TarjanResult bridgeRes = + graph.tarjan(CXXGraph::TARJAN_FIND_BRIDGE); + CXXGraph::TarjanResult vbccRes = + graph.tarjan(CXXGraph::TARJAN_FIND_VBCC); + CXXGraph::TarjanResult ebccRes = + graph.tarjan(CXXGraph::TARJAN_FIND_EBCC); + CXXGraph::TarjanResult res = + graph.tarjan(CXXGraph::TARJAN_FIND_CUTV | CXXGraph::TARJAN_FIND_BRIDGE | + CXXGraph::TARJAN_FIND_EBCC | CXXGraph::TARJAN_FIND_VBCC); ASSERT_EQ(res.success, true); ASSERT_EQ(res.cutVertices.size(), cutvRes.cutVertices.size()); @@ -356,18 +355,24 @@ TEST(TarjanTest, test_7) { for (int i = 0; i < bridgeRes.cutVertices.size(); ++i) { ASSERT_EQ(bridgeRes.bridges[i], res.bridges[i]); } - ASSERT_EQ(res.edgeBiconnectedComps.size(), ebccRes.edgeBiconnectedComps.size()); + ASSERT_EQ(res.edgeBiconnectedComps.size(), + ebccRes.edgeBiconnectedComps.size()); for (int i = 0; i < res.edgeBiconnectedComps.size(); ++i) { - ASSERT_EQ(res.edgeBiconnectedComps[i].size(), ebccRes.edgeBiconnectedComps[i].size()); + ASSERT_EQ(res.edgeBiconnectedComps[i].size(), + ebccRes.edgeBiconnectedComps[i].size()); for (int j = 0; j < ebccRes.edgeBiconnectedComps[i].size(); ++j) { - ASSERT_EQ(res.edgeBiconnectedComps[i][j], ebccRes.edgeBiconnectedComps[i][j]); + ASSERT_EQ(res.edgeBiconnectedComps[i][j], + ebccRes.edgeBiconnectedComps[i][j]); } } - ASSERT_EQ(res.verticeBiconnectedComps.size(), vbccRes.verticeBiconnectedComps.size()); + ASSERT_EQ(res.verticeBiconnectedComps.size(), + vbccRes.verticeBiconnectedComps.size()); for (int i = 0; i < res.verticeBiconnectedComps.size(); ++i) { - ASSERT_EQ(res.verticeBiconnectedComps[i].size(), vbccRes.verticeBiconnectedComps[i].size()); + ASSERT_EQ(res.verticeBiconnectedComps[i].size(), + vbccRes.verticeBiconnectedComps[i].size()); for (int j = 0; j < vbccRes.verticeBiconnectedComps[i].size(); ++j) { - ASSERT_EQ(res.verticeBiconnectedComps[i][j], vbccRes.verticeBiconnectedComps[i][j]); + ASSERT_EQ(res.verticeBiconnectedComps[i][j], + vbccRes.verticeBiconnectedComps[i][j]); } } } diff --git a/test/TopologicalSortTest.cpp b/test/TopologicalSortTest.cpp index 5aed68286..a81eb435d 100644 --- a/test/TopologicalSortTest.cpp +++ b/test/TopologicalSortTest.cpp @@ -1,4 +1,5 @@ #include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" @@ -6,10 +7,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; // topological sort test in a cyclic graph TEST(TopologicalSortTest, test_1) { diff --git a/test/TransitiveReductionTest.cpp b/test/TransitiveReductionTest.cpp index 4c12b8f0e..babd35520 100644 --- a/test/TransitiveReductionTest.cpp +++ b/test/TransitiveReductionTest.cpp @@ -1,8 +1,8 @@ +#include + #include "CXXGraph/CXXGraph.hpp" #include "gtest/gtest.h" -#include - template using shared = std::shared_ptr; using std::make_shared; diff --git a/test/UndirectedEdgeTest.cpp b/test/UndirectedEdgeTest.cpp index 7b5513838..243a879b1 100644 --- a/test/UndirectedEdgeTest.cpp +++ b/test/UndirectedEdgeTest.cpp @@ -5,10 +5,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(UndirectedEdgeTest, Constructor_1) { CXXGraph::Node node1("1", 1); @@ -74,8 +74,8 @@ TEST(UndirectedEdgeTest, Bool_data) { // Second constructor CXXGraph::Node node3("3", true); CXXGraph::Node node4("4", false); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::UndirectedEdge edge2(2, pairNode); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); @@ -97,8 +97,8 @@ TEST(UndirectedEdgeTest, String_data) { // Second constructor CXXGraph::Node node3("3", "On"); CXXGraph::Node node4("4", "Off"); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::UndirectedEdge edge2(2, pairNode); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); diff --git a/test/UndirectedWeightedEdgeTest.cpp b/test/UndirectedWeightedEdgeTest.cpp index 7349df589..3a081a8e8 100644 --- a/test/UndirectedWeightedEdgeTest.cpp +++ b/test/UndirectedWeightedEdgeTest.cpp @@ -5,10 +5,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(UndirectedWeightedEdgeTest, Constructor_1) { CXXGraph::Node node1("1", 1); @@ -107,8 +107,8 @@ TEST(UndirectedWeightedEdgeTest, Bool_data) { // Second constructor CXXGraph::Node node3("3", true); CXXGraph::Node node4("4", false); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::UndirectedWeightedEdge edge2(2, pairNode, 7); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); @@ -130,8 +130,8 @@ TEST(UndirectedWeightedEdgeTest, String_data) { // Second constructor CXXGraph::Node node3("3", "On"); CXXGraph::Node node4("4", "Off"); - std::pair *, const CXXGraph::Node *> pairNode( - &node3, &node4); + std::pair *, const CXXGraph::Node *> + pairNode(&node3, &node4); CXXGraph::UndirectedWeightedEdge edge2(2, pairNode, 5); /* ASSERT_EQ(edge2.getNodePair(), pairNode); */ ASSERT_EQ(*(edge2.getNodePair().first), node3); diff --git a/test/UnionFindTest.cpp b/test/UnionFindTest.cpp index e0cd80c6f..53328049d 100644 --- a/test/UnionFindTest.cpp +++ b/test/UnionFindTest.cpp @@ -5,10 +5,10 @@ template using unique = std::unique_ptr; template -using shared= std::shared_ptr; +using shared = std::shared_ptr; -using std::make_unique; using std::make_shared; +using std::make_unique; TEST(UnionFindTest, setFindTest1) { CXXGraph::Node node0("0", 0);