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); } } }
internal void Graph_ShouldContainSameSetOfEdges(GraphDefinitionParameter p) { // Arrange using MutableSimpleIncidenceGraph builder = new(p.VertexCount); foreach (Endpoints endpoints in p.Edges) { builder.Add(endpoints.Tail, endpoints.Head); } Graph graph = builder.ToGraph(); HashSet <Endpoints> expectedEdgeSet = p.Edges.ToHashSet(); // Act HashSet <Endpoints> actualEdgeSet = new(); for (int vertex = 0; vertex < graph.VertexCount; ++vertex) { EdgeEnumerator outEdges = graph.EnumerateOutEdges(vertex); while (outEdges.MoveNext()) { Endpoints edge = outEdges.Current; bool hasEndpoints = TryGetEndpoints(graph, edge, out Endpoints endpoints); if (!hasEndpoints) { Assert.True(hasEndpoints); } actualEdgeSet.Add(endpoints); } } // Assert Assert.Equal(expectedEdgeSet, actualEdgeSet, HashSetEqualityComparer); }