internal void Graph_ShouldContainSameSetOfEdges(GraphDefinitionParameter p) { // Arrange Graph.Builder builder = new(p.VertexCount, p.Edges.Count); 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()) { int 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); }
internal void Graph_OutEdgesShouldHaveSameTail(GraphDefinitionParameter p) { // Arrange Graph.UndirectedBuilder builder = new(p.VertexCount, p.Edges.Count); 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_SizeShouldMatch(GraphDefinitionParameter p) { // Arrange using Graph graph = new(p.VertexCount); foreach (Endpoints endpoints in p.Edges) { graph.Add(endpoints.Tail, endpoints.Head); } // Assert Assert.Equal(p.VertexCount, graph.VertexCount); Assert.Equal(p.Edges.Count, graph.EdgeCount); }
internal void Graph_SizeShouldMatch(GraphDefinitionParameter p) { // Arrange using MutableUndirectedSimpleIncidenceGraph builder = new(p.VertexCount); foreach (Endpoints endpoints in p.Edges) { builder.Add(endpoints.Tail, endpoints.Head); } // Act Graph graph = builder.ToGraph(); // Assert Assert.Equal(p.VertexCount, graph.VertexCount); Assert.Equal(p.Edges.Count, graph.EdgeCount); }
internal void Graph_ShouldContainSameSetOfEdges(GraphDefinitionParameter p) { // Arrange using Graph graph = new(p.VertexCount, p.Edges.Count); foreach (Endpoints endpoints in p.Edges) { graph.Add(endpoints.Tail, endpoints.Head); } HashSet <Endpoints> expectedEdgeSet = p.Edges.ToHashSet(); foreach (Endpoints edge in p.Edges) { if (edge.Tail == edge.Head) { continue; } Endpoints invertedEdge = new(edge.Head, edge.Tail); expectedEdgeSet.Add(invertedEdge); } // Act HashSet <Endpoints> actualEdgeSet = new(); for (int vertex = 0; vertex < graph.VertexCount; ++vertex) { EdgeEnumerator outEdges = graph.EnumerateOutEdges(vertex); while (outEdges.MoveNext()) { int edge = outEdges.Current; bool hasEndpoints = TryGetEndpoints(graph, edge, out Endpoints endpoints); if (!hasEndpoints) { Assert.True(hasEndpoints, $"{nameof(edge)}: {edge.ToString(F)}, {nameof(endpoints)}: {endpoints.ToString()}"); } actualEdgeSet.Add(endpoints); } } // Assert Assert.Equal(expectedEdgeSet, actualEdgeSet, HashSetEqualityComparer); }