MCPcopy Create free account
hub / github.com/apache/fory / ValidateGraph

Function ValidateGraph

integration_tests/idl_tests/cpp/main.cc:187–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187fory::Result<void, fory::Error> ValidateGraph(const graph::Graph &graph_value) {
188 const auto &nodes = graph_value.nodes();
189 const auto &edges = graph_value.edges();
190 if (nodes.size() != 2 || edges.size() != 1) {
191 return fory::Unexpected(fory::Error::invalid("graph size mismatch"));
192 }
193 const auto &node_a = nodes[0];
194 const auto &node_b = nodes[1];
195 const auto &edge = edges[0];
196 if (node_a->out_edges().empty() || node_a->in_edges().empty()) {
197 return fory::Unexpected(fory::Error::invalid("graph edge list empty"));
198 }
199 if (node_a->out_edges()[0] != node_a->in_edges()[0] ||
200 node_a->out_edges()[0] != edge) {
201 return fory::Unexpected(fory::Error::invalid("graph shared edge mismatch"));
202 }
203 auto from = edge->from().upgrade();
204 auto to = edge->to().upgrade();
205 if (!from || !to) {
206 return fory::Unexpected(fory::Error::invalid("graph weak upgrade failed"));
207 }
208 if (from != node_a || to != node_b) {
209 return fory::Unexpected(
210 fory::Error::invalid("graph edge endpoints mismatch"));
211 }
212 return fory::Result<void, fory::Error>();
213}
214
215} // namespace
216

Callers 1

RunRoundTripFunction · 0.85

Calls 5

UnexpectedClass · 0.85
sizeMethod · 0.45
emptyMethod · 0.45
upgradeMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected