Skip to content
Snippets Groups Projects
Commit 52860a57 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add CRSGraph tests

Also made a few cosmetic cleanups
parent 006a7f63
No related branches found
No related tags found
1 merge request!63Feature/utils coverage
......@@ -6,8 +6,8 @@
class CRSGraph
{
private:
Array<int> m_entries;
Array<int> m_neighbors;
Array<const int> m_entries;
Array<const int> m_neighbors;
public:
size_t
......@@ -17,29 +17,30 @@ class CRSGraph
return m_entries.size() - 1;
}
const Array<int>&
const Array<const int>&
entries() const
{
return m_entries;
}
const Array<int>&
const Array<const int>&
neighbors() const
{
return m_neighbors;
}
CRSGraph& operator=(CRSGraph&&) = default;
CRSGraph& operator=(const CRSGraph&) = default;
CRSGraph& operator=(CRSGraph&&) = delete;
CRSGraph& operator=(const CRSGraph&) = delete;
CRSGraph(const Array<int>& entries, const Array<int>& neighbors) : m_entries(entries), m_neighbors(neighbors)
{
Assert(m_entries.size() > 0);
Assert(static_cast<size_t>(m_entries[m_entries.size() - 1]) == m_neighbors.size());
}
CRSGraph() = default;
CRSGraph(CRSGraph&&) = default;
CRSGraph(const CRSGraph&) = default;
CRSGraph() = delete;
CRSGraph(CRSGraph&&) = delete;
CRSGraph(const CRSGraph&) = delete;
~CRSGraph() = default;
};
......
......@@ -57,11 +57,14 @@ Partitioner::partition(const CRSGraph& graph)
part = Array<int>(local_number_of_nodes);
std::vector<int> vtxdist{0, local_number_of_nodes};
const Array<int>& entries = graph.entries();
const Array<int>& neighbors = graph.neighbors();
const Array<const int>& entries = graph.entries();
const Array<const int>& neighbors = graph.neighbors();
int* entries_ptr = const_cast<int*>(&(entries[0]));
int* neighbors_ptr = const_cast<int*>(&(neighbors[0]));
int result =
ParMETIS_V3_PartKway(&(vtxdist[0]), &(entries[0]), &(neighbors[0]), NULL, NULL, &wgtflag, &numflag, &ncon, &npart,
ParMETIS_V3_PartKway(&(vtxdist[0]), entries_ptr, neighbors_ptr, NULL, NULL, &wgtflag, &numflag, &ncon, &npart,
&(tpwgts[0]), &(ubvec[0]), &(options[0]), &edgecut, &(part[0]), &parmetis_comm);
if (result == METIS_ERROR) {
throw UnexpectedError("Metis Error");
......
......@@ -52,6 +52,7 @@ add_executable (unit_tests
test_CG.cpp
test_ContinueProcessor.cpp
test_ConcatExpressionProcessor.cpp
test_CRSGraph.cpp
test_CRSMatrix.cpp
test_DataVariant.cpp
test_DoWhileProcessor.cpp
......
#ifndef TEST_CRS_GRAPH_HPP
#define TEST_CRS_GRAPH_HPP
#include <catch2/catch.hpp>
#include <utils/CRSGraph.hpp>
// clazy:excludeall=non-pod-global-static
TEST_CASE("CRSGraph", "[utils]")
{
Array<int> entries{5};
Array<int> neighbors{9};
entries[0] = 0;
neighbors[0] = 0;
neighbors[1] = 1;
entries[1] = 2;
neighbors[2] = 1;
neighbors[3] = 3;
entries[2] = 4;
neighbors[4] = 2;
neighbors[5] = 1;
neighbors[6] = 3;
entries[3] = 7;
neighbors[7] = 0;
neighbors[8] = 1;
entries[4] = 9;
CRSGraph graph(entries, neighbors);
REQUIRE(graph.numberOfNodes() == 4);
REQUIRE(entries.size() == graph.entries().size());
REQUIRE(&entries[0] == &graph.entries()[0]);
REQUIRE(neighbors.size() == graph.neighbors().size());
REQUIRE(&neighbors[0] == &graph.neighbors()[0]);
}
#endif // TEST_CRS_GRAPH_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment