public void AddUndirectedEdge_ShouldThrowKeyNotFoundException_WhenNotExistingKeySpecified(UndirectedGraph <int> graph, int source, int destination) { Assert.Throws <KeyNotFoundException>(() => { graph.AddUndirectedEdge(source, destination); }); }
public void AddUndirectedEdge_ShouldThrowInvalidOperationException_WhenEdgeCreatesLoopOrMultipleEdge(UndirectedGraph <int> graph, int source, int destination) { Assert.Throws <InvalidOperationException>(() => { graph.AddUndirectedEdge(source, destination); }); }
public IEnumerable <TVertex> Execute(TGraph graph) { if (graph == null) { throw new ArgumentNullException(nameof(graph)); } if (_connectedComponentsCounter.Execute(graph) > 1) { throw new InvalidOperationException("Target graph should be highly connected for searching articulation points in it"); } var foundArticulationPoints = new List <TVertex>(); // Cloning graph to save the original one var graphClone = new UndirectedGraph <TVertex>(graph.Vertices, graph.ReducedEdges) as TGraph; var graphVertices = graphClone.Vertices.ToList(); foreach (var vertex in graphVertices) { var sourceEdges = graphClone.Edges.Where(e => e.Source.CompareTo(vertex) == 0); var destinationEdges = graphClone.Edges.Where(e => e.Destination.CompareTo(vertex) == 0); graphClone.RemoveVertex(vertex); if (_connectedComponentsCounter.Execute(graphClone) > 1) { foundArticulationPoints.Add(vertex); } graphClone.AddVertex(vertex); foreach (var edge in sourceEdges) { graphClone.AddUndirectedEdge(edge.Source, edge.Destination); } } return(foundArticulationPoints); }