public void RemoveDirectedEdge_ShouldThrowKeyNotFoundException_WhenNotExistingKeySpecified(MixedGraph <int> graph, int source, int destination) { Assert.Throws <KeyNotFoundException>(() => { graph.RemoveDirectedEdge(source, destination); }); }
public void RemoveDirectedEdge_ShouldRemoveConnectedVertexFromAdjacencyLists_WhenExistingKeysSpecified( MixedGraph <int> graph, int sourceToRemove, int destinationToRemove, Dictionary <int, IReadOnlyList <int> > expectedAdjacencyLists) { graph.RemoveDirectedEdge(sourceToRemove, destinationToRemove); Assert.Equal(expectedAdjacencyLists, graph.AdjacencyLists); }
/// <summary> /// Performs depth-first search on graph, orienting each visited edge against its direction /// </summary> /// <param name="graph">Graph</param> /// <param name="sourceVertex">Current vertex</param> /// <param name="visitedVertices">Visited vertices</param> private void DfsGraphAndRemoveVisitedEdges(MixedGraph <TVertex> graph, TVertex sourceVertex, ISet <TVertex> visitedVertices) { var notVisitedNeighbourVertices = graph.AdjacencyLists[sourceVertex].ToList(); foreach (var neighbourVertex in notVisitedNeighbourVertices) { if (!visitedVertices.Contains(neighbourVertex)) { visitedVertices.Add(neighbourVertex); graph.RemoveDirectedEdge(sourceVertex, neighbourVertex); DfsGraphAndRemoveVisitedEdges(graph, neighbourVertex, visitedVertices); } } }