internal void Graph_OutEdgesShouldHaveSameTail(GraphDefinitionParameter p) { // Arrange using MutableUndirectedSimpleIncidenceGraph builder = new(p.VertexCount); foreach (Endpoints endpoints in p.Edges) { builder.Add(endpoints.Tail, endpoints.Head); } Graph graph = builder.ToGraph(); // Act for (int vertex = 0; vertex < graph.VertexCount; ++vertex) { EdgeEnumerator outEdges = graph.EnumerateOutEdges(vertex); while (outEdges.MoveNext()) { Endpoints edge = outEdges.Current; bool hasTail = graph.TryGetTail(edge, out int tail); if (!hasTail) { Assert.True(hasTail); } // Assert Assert.Equal(vertex, tail); } } }
private static bool TryGetEndpoints(Graph graph, Endpoints edge, out Endpoints endpoints) { bool hasTail = graph.TryGetTail(edge, out int tail); bool hasHead = graph.TryGetHead(edge, out int head); endpoints = new Endpoints(tail, head); return(hasTail && hasHead); }