Skip to content

Commit 2c633f5

Browse files
committed
added a jank component set check
1 parent 026f837 commit 2c633f5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

include/test/graph_verifier.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class GraphVerifier {
6161
*/
6262
void verify_connected_components(const ConnectedComponents &cc);
6363

64+
/**
65+
* Verifies the connected components solution is correct. Compares
66+
* retval against kruskal_ref.
67+
* @throws IncorrectCCException if the solution cannot be verified
68+
*/
69+
void verify_cc_from_component_set(std::vector<std::set<node_id_t>> component_set);
70+
6471
/**
6572
* Verifies that one or more spanning forests are valid
6673
* Additionally, enforces that spanning forests must be edge disjoint.

test/util/graph_verifier.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ void GraphVerifier::verify_connected_components(const ConnectedComponents &cc) {
106106
}
107107
}
108108

109+
void GraphVerifier::verify_cc_from_component_set(std::vector<std::set<node_id_t>> component_set) {
110+
// compute the connected components for the verifier
111+
kruskal();
112+
113+
// first check that the number of components is the same for both
114+
if (kruskal_ccs != component_set.size()) {
115+
throw IncorrectCCException("Incorrect number of components!");
116+
}
117+
// then check that we agree on where all the vertices belong
118+
for (auto &component : component_set) {
119+
node_id_t first = *component.begin();
120+
node_id_t root = kruskal_dsu.find_root(first);
121+
for (auto &node : component) {
122+
if (kruskal_dsu.find_root(node) != root) {
123+
throw IncorrectCCException("Incorrect Connectivity!");
124+
}
125+
}
126+
}
127+
}
128+
109129
void GraphVerifier::verify_spanning_forests(std::vector<SpanningForest> SFs) {
110130
// backup the adjacency matrix
111131
std::vector<std::vector<bool>> backup(adj_matrix);

0 commit comments

Comments
 (0)