protected static void TryGetOutEdges_Test( [NotNull] IMutableVertexAndEdgeListGraph <int, Edge <int> > graph) { TryGetOutEdges_Test( graph, edges => graph.AddVerticesAndEdgeRange(edges)); }
protected static void RemoveOutEdgeIf_Test( [NotNull] IMutableVertexAndEdgeListGraph <int, Edge <int> > graph) { int verticesRemoved = 0; int edgesRemoved = 0; // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local graph.VertexRemoved += v => { Assert.IsNotNull(v); ++verticesRemoved; }; // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local graph.EdgeRemoved += e => { Assert.IsNotNull(e); // ReSharper disable once AccessToModifiedClosure ++edgesRemoved; }; Assert.AreEqual(0, graph.RemoveOutEdgeIf(1, _ => true)); CheckCounters(0); AssertEmptyGraph(graph); var edge12 = new Edge <int>(1, 2); var edge13 = new Edge <int>(1, 3); var edge13Bis = new Edge <int>(1, 3); var edge14 = new Edge <int>(1, 4); var edge24 = new Edge <int>(2, 4); var edge31 = new Edge <int>(3, 1); var edge33 = new Edge <int>(3, 3); graph.AddVerticesAndEdgeRange(new[] { edge12, edge13, edge13Bis, edge14, edge24, edge31, edge33 }); Assert.AreEqual(3, graph.RemoveOutEdgeIf(1, edge => edge.Target >= 3)); CheckCounters(3); AssertHasVertices(graph, new[] { 1, 2, 3, 4 }); AssertHasEdges(graph, new[] { edge12, edge24, edge31, edge33 }); Assert.AreEqual(0, graph.RemoveOutEdgeIf(3, edge => edge.Target > 5)); CheckCounters(0); AssertHasVertices(graph, new[] { 1, 2, 3, 4 }); AssertHasEdges(graph, new[] { edge12, edge24, edge31, edge33 }); Assert.AreEqual(2, graph.RemoveOutEdgeIf(3, _ => true)); CheckCounters(2); AssertHasVertices(graph, new[] { 1, 2, 3, 4 }); AssertHasEdges(graph, new[] { edge12, edge24 }); #region Local function void CheckCounters(int expectedRemovedEdges) { Assert.AreEqual(0, verticesRemoved); Assert.AreEqual(expectedRemovedEdges, edgesRemoved); edgesRemoved = 0; } #endregion }
protected static void OutEdge_Test( IMutableVertexAndEdgeListGraph <int, Edge <int> > graph) { OutEdge_Test( graph, edges => graph.AddVerticesAndEdgeRange(edges)); }
public static void BuildConnectedOutSubGraph <TVertex, TEdge>( this IVertexAndEdgeListGraph <TVertex, TEdge> graph, IMutableVertexAndEdgeListGraph <TVertex, TEdge> subGraph, IEnumerable <TVertex> entries, Func <TVertex, TVertex, TEdge> edgeFactory) where TEdge : IEdge <TVertex> { var reachable = graph.FindReachable(entries); var neededEdges = graph.GetAllEdges(reachable).ToList(); subGraph.AddVerticesAndEdgeRange(neededEdges); }