Skip to content

Commit

Permalink
cleanup and validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Nov 25, 2024
1 parent 41ed0b8 commit f434a39
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,27 @@ private void degreeTwoMerge() {
for (var node : output) {
degreeTwoMerge(node);
}
output.removeIf(node -> node.getEdges().isEmpty());
assert valid();
}

private boolean valid() {
// when run from a unit test, ensure some basic conditions always hold...
for (var node : output) {
for (var edge : node.getEdges()) {
assert edge.isLoop() || edge.to.getEdges().contains(edge.reversed) : edge.to + " does not contain " +
edge.reversed;
for (var other : node.getEdges()) {
if (edge != other) {
assert edge != other.reversed : "node contained edge and its reverse " + node;
assert !edge.coordinates.equals(other.coordinates) : "duplicate edges " + edge + " and " + other;
}
}
}
assert node.getEdges().size() != 2 || node.getEdges().stream().anyMatch(Edge::isLoop) : "degree 2 node found " +
node;
}
return true;
}

private Edge degreeTwoMerge(Node node) {
Expand Down

0 comments on commit f434a39

Please sign in to comment.