Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings in compilation of tests #460

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/CXXGraph/Graph/Algorithm/BellmanFord_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const BellmanFordResult Graph<T>::bellmanford(const Node<T> &source,
// iterations remain the same.
auto earlyStopping = false;
// outer loop for vertex relaxation
for (int i = 0; i < n - 1; ++i) {
for (size_t i = 0; i < n - 1; ++i) {
auto edgeSet = Graph<T>::getEdgeSet();
// inner loop for distance updates of
// each relaxation
Expand Down
4 changes: 2 additions & 2 deletions include/CXXGraph/Graph/Algorithm/BestFirstSearch_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const std::vector<Node<T>> Graph<T>::concurrency_breadth_first_search(

// last worker need to do preparation for the next iteration
int cur_level = level;
if (num_threads == 1 + waiting_workers.fetch_add(1)) {
if (num_threads == 1u + waiting_workers.fetch_add(1u)) {
swap(level_tracker, next_level_tracker);
next_level_tracker.clear();

Expand Down Expand Up @@ -240,7 +240,7 @@ const std::vector<Node<T>> Graph<T>::concurrency_breadth_first_search(
};

std::vector<std::thread> workers;
for (int i = 0; i < num_threads - 1; ++i) {
for (size_t i = 0; i < num_threads - 1; ++i) {
workers.emplace_back(std::thread(bfs_worker));
}
bfs_worker();
Expand Down
6 changes: 3 additions & 3 deletions include/CXXGraph/Graph/Algorithm/Connectivity_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool Graph<T>::isConnectedGraph() const {
visited[source->getId()] = true;

// travel the neighbors
for (int i = 0; i < (*cachedAdjMatrix)[source].size(); i++) {
for (size_t i = 0; i < (*cachedAdjMatrix)[source].size(); i++) {
shared<const Node<T>> neighbor =
(*cachedAdjMatrix)[source].at(i).first;
if (visited[neighbor->getId()] == false) {
Expand Down Expand Up @@ -83,7 +83,7 @@ bool Graph<T>::isStronglyConnectedGraph() const {
visited[source->getId()] = true;

// travel the neighbors
for (int i = 0; i < (*cachedAdjMatrix)[source].size(); i++) {
for (size_t i = 0; i < (*cachedAdjMatrix)[source].size(); i++) {
shared<const Node<T>> neighbor =
(*cachedAdjMatrix)[source].at(i).first;
if (visited[neighbor->getId()] == false) {
Expand All @@ -106,4 +106,4 @@ bool Graph<T>::isStronglyConnectedGraph() const {
}
}
} // namespace CXXGraph
#endif // __CXXGRAPH_CONNECTIVITY_IMPL_H__
#endif // __CXXGRAPH_CONNECTIVITY_IMPL_H__
2 changes: 1 addition & 1 deletion include/CXXGraph/Graph/Algorithm/Dial_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const DialResult Graph<T>::dial(const Node<T> &source, int maxWeight) const {
B[0].push_back(*source_node_it);
dist[*source_node_it].first = 0;

int idx = 0;
std::size_t idx = 0;
while (true) {
// Go sequentially through buckets till one non-empty
// bucket is found
Expand Down
9 changes: 6 additions & 3 deletions include/CXXGraph/Graph/Algorithm/Dijkstra_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const DijkstraResult Graph<T>::dijkstra(const Node<T>& source,
return result;
}
// n denotes the number of vertices in graph
auto n = cachedAdjMatrix->size();
// unused
//auto n = cachedAdjMatrix->size();

// setting all the distances initially to INF_DOUBLE
std::unordered_map<shared<const Node<T>>, double, nodeHash<T>> dist;
Expand Down Expand Up @@ -175,7 +176,8 @@ const DijkstraResult Graph<T>::dijkstra_deterministic(
return result;
}
// n denotes the number of vertices in graph
auto n = cachedAdjMatrix->size();
// unused
//auto n = cachedAdjMatrix->size();

// setting all the distances initially to INF_DOUBLE
std::unordered_map<shared<const Node<T>>, double, nodeHash<T>> dist;
Expand Down Expand Up @@ -322,7 +324,8 @@ const DijkstraResult Graph<T>::dijkstra_deterministic2(
return result;
}
// n denotes the number of vertices in graph
auto n = cachedAdjMatrix->size();
// unused
// auto n = cachedAdjMatrix->size();

// setting all the distances initially to INF_DOUBLE
std::unordered_map<shared<const Node<T>>, double, nodeHash<T>> dist;
Expand Down
6 changes: 3 additions & 3 deletions include/CXXGraph/Graph/Algorithm/Kosaraju_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SCCResult<T> Graph<T>::kosaraju() const {
visited[source->getId()] = true;

// travel the neighbors
for (int i = 0; i < (*cachedAdjMatrix)[source].size(); i++) {
for (size_t i = 0; i < (*cachedAdjMatrix)[source].size(); i++) {
shared<const Node<T>> neighbor =
(*cachedAdjMatrix)[source].at(i).first;
if (visited[neighbor->getId()] == false) {
Expand Down Expand Up @@ -99,7 +99,7 @@ SCCResult<T> Graph<T>::kosaraju() const {
result.sccMap[source->getId()] = sccLabel;

// travel the neighbors
for (int i = 0; i < rev[source].size(); i++) {
for (size_t i = 0; i < rev[source].size(); i++) {
shared<const Node<T>> neighbor = rev[source].at(i).first;
if (visited[neighbor->getId()] == false) {
// make recursive call from neighbor
Expand All @@ -125,4 +125,4 @@ SCCResult<T> Graph<T>::kosaraju() const {
}
}
} // namespace CXXGraph
#endif // __CXXGRAPH_KOSARAJU_IMPL_H__
#endif // __CXXGRAPH_KOSARAJU_IMPL_H__
5 changes: 3 additions & 2 deletions include/CXXGraph/Graph/Algorithm/Prim_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const MstResult Graph<T>::prim() const {
return result;
}
auto nodeSet = Graph<T>::getNodeSet();
auto n = nodeSet.size();
// unused
/* auto n = nodeSet.size(); */

// setting all the distances initially to INF_DOUBLE
std::unordered_map<shared<const Node<T>>, double, nodeHash<T>> dist;
Expand Down Expand Up @@ -109,4 +110,4 @@ const MstResult Graph<T>::prim() const {
return result;
}
} // namespace CXXGraph
#endif // __CXXGRAPH_PRIM_IMPL_H__
#endif // __CXXGRAPH_PRIM_IMPL_H__
3 changes: 2 additions & 1 deletion include/CXXGraph/Graph/Graph_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ std::shared_ptr<std::vector<Node<T>>> Graph<T>::eulerianPath() const {
std::shared_ptr<std::vector<Node<T>>> eulerPath =
std::make_shared<std::vector<Node<T>>>();

bool undirected = this->isUndirectedGraph();
// unused
// bool undirected = this->isUndirectedGraph();

std::vector<shared<const Node<T>>> currentPath;
// The starting node is the only node which has more outgoing than ingoing
Expand Down
12 changes: 6 additions & 6 deletions include/CXXGraph/Graph/IO/InputOperation_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ int Graph<T>::readFromMTXFile(const std::string &workingDir,
}

// Define the number of columns and rows in the matrix
int n_cols, n_rows;
int n_edges;
std::size_t n_cols, n_rows;
std::size_t n_edges;
bool undirected = false;

// From the first line of the file read the number of rows, columns and edges
Expand All @@ -201,11 +201,11 @@ int Graph<T>::readFromMTXFile(const std::string &workingDir,
std::stringstream header_stream(row_content);
std::string value;
getline(header_stream, value, ' ');
n_rows = std::stoi(value);
n_rows = std::stoul(value);
getline(header_stream, value, ' ');
n_cols = std::stoi(value);
n_cols = std::stoul(value);
getline(header_stream, value, ' ');
n_edges = std::stoi(value);
n_edges = std::stoul(value);

// Since the matrix represents the adjacency matrix, it must be square
if (n_rows != n_cols) {
Expand Down Expand Up @@ -434,4 +434,4 @@ void Graph<T>::recreateGraph(
}

} // namespace CXXGraph
#endif // __CXXGRAPH_INPUTOPERATION_IMPL_H__
#endif // __CXXGRAPH_INPUTOPERATION_IMPL_H__
6 changes: 3 additions & 3 deletions include/CXXGraph/Graph/IO/OutputOperation_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ int Graph<T>::writeToFile(InputOutputFormat format,
return _result;
};
if (format == InputOutputFormat::STANDARD_CSV) {
auto result = _compress(".csv");
result = _compress(".csv");
} else if (format == InputOutputFormat::STANDARD_TSV) {
auto result = _compress(".tsv");
result = _compress(".tsv");
} else {
// OUTPUT FORMAT NOT RECOGNIZED
result = -1;
Expand Down Expand Up @@ -285,4 +285,4 @@ void Graph<T>::writeGraphToStream(std::ostream &oGraph, std::ostream &oNodeFeat,
}

} // namespace CXXGraph
#endif // __CXXGRAPH_OUTPUTOPERATION_IMPL_H__
#endif // __CXXGRAPH_OUTPUTOPERATION_IMPL_H__
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int CoordinatedPartitionState<T>::getMachineWithMinWeight() const {

double MIN_LOAD = std::numeric_limits<double>::max();
int machine_id = 0;
for (int i = 0; i < machines_weight_edges.size(); ++i) {
for (size_t i = 0; i < machines_weight_edges.size(); ++i) {
double loadi = machines_weight_edges[i];
if (loadi < MIN_LOAD) {
MIN_LOAD = loadi;
Expand Down
2 changes: 1 addition & 1 deletion test/BFSTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ TEST(BFSTest, test_13) {
edgeSet.insert(newEdge);
}
}
for (int i = 1; i < nodes.size(); i += 2) {
for (size_t i = 1; i < nodes.size(); i += 2) {
shared<CXXGraph::UndirectedEdge<int>> newEdge =
make_shared<CXXGraph::UndirectedEdge<int>>(
edges_size + i + 1, *(nodes.at(0)), *(nodes.at(i)));
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ endif(CODE_COVERAGE)
option(TEST "Enable Test" OFF)
if(TEST)
include(${CPM_DOWNLOAD_LOCATION})
add_compile_options(
-Wall
-Wextra
)

CPMAddPackage(
NAME googletest
Expand Down
4 changes: 2 additions & 2 deletions test/KahnTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TEST(KahnTest, correct_example_small) {
ASSERT_EQ(res.nodesInTopoOrder.size(), graph.getNodeSet().size());

std::unordered_map<CXXGraph::id_t, int> topOrderNodeIds;
for (int i = 0; i < res.nodesInTopoOrder.size(); ++i) {
for (size_t i = 0; i < res.nodesInTopoOrder.size(); ++i) {
topOrderNodeIds[res.nodesInTopoOrder[i].getId()] = i;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ TEST(KahnTest, correct_example_big) {
ASSERT_EQ(res.nodesInTopoOrder.size(), graph.getNodeSet().size());

std::unordered_map<CXXGraph::id_t, int> topOrderNodeIds;
for (int i = 0; i < res.nodesInTopoOrder.size(); ++i) {
for (size_t i = 0; i < res.nodesInTopoOrder.size(); ++i) {
topOrderNodeIds[res.nodesInTopoOrder[i].getId()] = i;
}

Expand Down
4 changes: 2 additions & 2 deletions test/KosarajuTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void compareComponents(CXXGraph::SCCResult<int> result,
CXXGraph::Components<int>& comp2) {
ASSERT_EQ(result.noOfComponents, comp2.size());

for (int i = 0; i < comp2.size(); i++) {
for (size_t i = 0; i < comp2.size(); i++) {
int curComp = result.sccMap[comp2[i][0].getId()];
for (int j = 1; j < comp2[i].size(); j++) {
for (size_t j = 1; j < comp2[i].size(); j++) {
ASSERT_EQ(result.sccMap[comp2[i][j].getId()], curComp);
}
}
Expand Down
38 changes: 19 additions & 19 deletions test/TarjanTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ TEST(TarjanTest, test_2) {
}
std::vector<std::vector<CXXGraph::Node<int>>> expectRes{
{node9}, {node4, node5}, {node1, node2, node3}, {node6, node7, node8}};
for (int i = 0; i < 4; ++i) {
for (short i = 0; i < 4; ++i) {
ASSERT_EQ(res.stronglyConnectedComps[i].size(), expectRes[i].size());
for (int j = 0; j < expectRes[i].size(); ++j) {
for (size_t j = 0; j < expectRes[i].size(); ++j) {
ASSERT_EQ(res.stronglyConnectedComps[i][j], expectRes[i][j]);
}
}
Expand All @@ -113,7 +113,7 @@ TEST(TarjanTest, test_3) {
// https://en.wikipedia.org/wiki/Biconnected_component#/media/File:Block-cut_tree2.svg
std::vector<CXXGraph::Node<int>> nodes;
nodes.emplace_back("0", 0);
for (int i = 1; i <= 18; ++i) {
for (short i = 1; i <= 18; ++i) {
nodes.emplace_back(std::to_string(i), i);
};
std::vector<std::pair<int, int>> pairs{
Expand All @@ -139,7 +139,7 @@ TEST(TarjanTest, test_3) {
[&](const auto &node1, const auto &node2) {
return node1.getData() < node2.getData();
});
for (int i = 0; i < expectRes.size(); ++i) {
for (size_t i = 0; i < expectRes.size(); ++i) {
ASSERT_EQ(res.cutVertices[i], nodes[expectRes[i]]);
}
// check whether other types of functions are not be executed
Expand All @@ -154,7 +154,7 @@ TEST(TarjanTest, test_4) {
// https://en.wikipedia.org/wiki/Biconnected_component#/media/File:Block-cut_tree2.svg
std::vector<CXXGraph::Node<int>> nodes;
nodes.emplace_back("0", 0);
for (int i = 1; i <= 18; ++i) {
for (short i = 1; i <= 18; ++i) {
nodes.emplace_back(std::to_string(i), i);
};
std::vector<std::pair<int, int>> pairs{
Expand Down Expand Up @@ -200,9 +200,9 @@ TEST(TarjanTest, test_4) {
}
return scc1[0].getData() < scc2[0].getData();
});
for (int i = 0; i < res.verticeBiconnectedComps.size(); ++i) {
for (size_t i = 0; i < res.verticeBiconnectedComps.size(); ++i) {
ASSERT_EQ(res.verticeBiconnectedComps[i].size(), expectRes[i].size());
for (int j = 0; j < expectRes[i].size(); ++j) {
for (size_t j = 0; j < expectRes[i].size(); ++j) {
ASSERT_EQ(res.verticeBiconnectedComps[i][j], expectRes[i][j]);
}
}
Expand All @@ -218,7 +218,7 @@ TEST(TarjanTest, test_5) {
// codeforce https://codeforces.com/blog/entry/99259
std::vector<CXXGraph::Node<int>> nodes;
nodes.emplace_back("0", 0);
for (int i = 1; i <= 12; ++i) {
for (short i = 1; i <= 12; ++i) {
nodes.emplace_back(std::to_string(i), i);
};
std::vector<std::pair<int, int>> pairs{
Expand All @@ -243,7 +243,7 @@ TEST(TarjanTest, test_5) {
[&](const auto &edge1, const auto &edge2) {
return edge1.getId() < edge2.getId();
});
for (int i = 0; i < expectRes.size(); ++i) {
for (size_t i = 0; i < expectRes.size(); ++i) {
ASSERT_EQ(res.bridges[i], edges[expectRes[i]]);
}
// check whether other types of functions are not be executed
Expand All @@ -258,7 +258,7 @@ TEST(TarjanTest, test_6) {
// codeforce https://codeforces.com/blog/entry/99259
std::vector<CXXGraph::Node<int>> nodes;
nodes.emplace_back("0", 0);
for (int i = 1; i <= 12; ++i) {
for (short i = 1; i <= 12; ++i) {
nodes.emplace_back(std::to_string(i), i);
};
std::vector<std::pair<int, int>> pairs{
Expand Down Expand Up @@ -298,9 +298,9 @@ TEST(TarjanTest, test_6) {
}
return scc1[0].getData() < scc2[0].getData();
});
for (int i = 0; i < res.edgeBiconnectedComps.size(); ++i) {
for (size_t i = 0; i < res.edgeBiconnectedComps.size(); ++i) {
ASSERT_EQ(res.edgeBiconnectedComps[i].size(), expectRes[i].size());
for (int j = 0; j < expectRes[i].size(); ++j) {
for (size_t j = 0; j < expectRes[i].size(); ++j) {
ASSERT_EQ(res.edgeBiconnectedComps[i][j], expectRes[i][j]);
}
}
Expand All @@ -316,7 +316,7 @@ TEST(TarjanTest, test_7) {
// https://en.wikipedia.org/wiki/Biconnected_component#/media/File:Block-cut_tree2.svg
std::vector<CXXGraph::Node<int>> nodes;
nodes.emplace_back("0", 0);
for (int i = 1; i <= 18; ++i) {
for (short i = 1; i <= 18; ++i) {
nodes.emplace_back(std::to_string(i), i);
};
std::vector<std::pair<int, int>> pairs{
Expand Down Expand Up @@ -348,29 +348,29 @@ TEST(TarjanTest, test_7) {
ASSERT_EQ(res.success, true);

ASSERT_EQ(res.cutVertices.size(), cutvRes.cutVertices.size());
for (int i = 0; i < cutvRes.cutVertices.size(); ++i) {
for (size_t i = 0; i < cutvRes.cutVertices.size(); ++i) {
ASSERT_EQ(cutvRes.cutVertices[i], res.cutVertices[i]);
}
ASSERT_EQ(res.bridges.size(), bridgeRes.bridges.size());
for (int i = 0; i < bridgeRes.cutVertices.size(); ++i) {
for (size_t i = 0; i < bridgeRes.cutVertices.size(); ++i) {
ASSERT_EQ(bridgeRes.bridges[i], res.bridges[i]);
}
ASSERT_EQ(res.edgeBiconnectedComps.size(),
ebccRes.edgeBiconnectedComps.size());
for (int i = 0; i < res.edgeBiconnectedComps.size(); ++i) {
for (size_t i = 0; i < res.edgeBiconnectedComps.size(); ++i) {
ASSERT_EQ(res.edgeBiconnectedComps[i].size(),
ebccRes.edgeBiconnectedComps[i].size());
for (int j = 0; j < ebccRes.edgeBiconnectedComps[i].size(); ++j) {
for (size_t j = 0; j < ebccRes.edgeBiconnectedComps[i].size(); ++j) {
ASSERT_EQ(res.edgeBiconnectedComps[i][j],
ebccRes.edgeBiconnectedComps[i][j]);
}
}
ASSERT_EQ(res.verticeBiconnectedComps.size(),
vbccRes.verticeBiconnectedComps.size());
for (int i = 0; i < res.verticeBiconnectedComps.size(); ++i) {
for (size_t i = 0; i < res.verticeBiconnectedComps.size(); ++i) {
ASSERT_EQ(res.verticeBiconnectedComps[i].size(),
vbccRes.verticeBiconnectedComps[i].size());
for (int j = 0; j < vbccRes.verticeBiconnectedComps[i].size(); ++j) {
for (size_t j = 0; j < vbccRes.verticeBiconnectedComps[i].size(); ++j) {
ASSERT_EQ(res.verticeBiconnectedComps[i][j],
vbccRes.verticeBiconnectedComps[i][j]);
}
Expand Down
2 changes: 1 addition & 1 deletion test/TopologicalSortTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ TEST(TopologicalSortTest, test_3) {

// check topological order of nodes
std::unordered_map<CXXGraph::id_t, int> nodeToOrder;
for (int i = 0; i < res.nodesInTopoOrder.size(); ++i) {
for (size_t i = 0; i < res.nodesInTopoOrder.size(); ++i) {
nodeToOrder[res.nodesInTopoOrder[i].getId()] = i;
}

Expand Down
Loading