protected static void RemoveVertex_Throws_Clusters_Test <TVertex, TEdge>(
     [NotNull] ClusteredAdjacencyGraph <TVertex, TEdge> graph)
     where TVertex : class
     where TEdge : IEdge <TVertex>
 {
     // ReSharper disable once AssignNullToNotNullAttribute
     Assert.Throws <ArgumentNullException>(() => graph.RemoveVertex(null));
 }
Example #2
0
        public void RemovingClusterVertex()
        {
            var graph          = new AdjacencyGraph <int, IEdge <int> >();
            var clusteredGraph = new ClusteredAdjacencyGraph <int, IEdge <int> >(graph);
            ClusteredAdjacencyGraph <int, IEdge <int> > cluster1 = clusteredGraph.AddCluster();
            ClusteredAdjacencyGraph <int, IEdge <int> > cluster2 = cluster1.AddCluster();
            ClusteredAdjacencyGraph <int, IEdge <int> > cluster3 = cluster2.AddCluster();

            cluster3.AddVertex(5);
            cluster2.RemoveVertex(5);

            Assert.IsFalse(ContainsVertexParent(cluster3, 5));
        }
        protected static void RemoveVertex_Clusters_Test(
            [NotNull] ClusteredAdjacencyGraph <int, Edge <int> > graph)
        {
            var edge12 = new Edge <int>(1, 2);
            var edge13 = 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, edge14, edge24, edge31, edge33 });

            Assert.IsFalse(graph.RemoveVertex(5));

            Assert.IsTrue(graph.RemoveVertex(3));
            AssertHasVertices(graph, new[] { 1, 2, 4 });
            AssertHasEdges(graph, new[] { edge12, edge14, edge24 });

            Assert.IsTrue(graph.RemoveVertex(1));
            AssertHasVertices(graph, new[] { 2, 4 });
            AssertHasEdges(graph, new[] { edge24 });

            Assert.IsTrue(graph.RemoveVertex(2));
            AssertHasVertices(graph, new[] { 4 });
            AssertNoEdge(graph);

            Assert.IsTrue(graph.RemoveVertex(4));
            AssertEmptyGraph(graph);


            // With cluster
            ClusteredAdjacencyGraph <int, Edge <int> > cluster1 = graph.AddCluster();
            ClusteredAdjacencyGraph <int, Edge <int> > cluster2 = graph.AddCluster();
            ClusteredAdjacencyGraph <int, Edge <int> > cluster3 = graph.AddCluster();

            cluster1.AddVertexRange(new[] { 1, 2 });
            AssertHasVertices(cluster1, new[] { 1, 2 });

            cluster2.AddVertexRange(new[] { 1, 2, 4 });
            AssertHasVertices(cluster2, new[] { 1, 2, 4 });

            cluster3.AddVertex(2);
            AssertHasVertices(cluster3, new[] { 2 });

            graph.AddVertexRange(new[] { 1, 2, 3, 4 });
            AssertHasVertices(graph, new[] { 1, 2, 3, 4 });


            graph.RemoveVertex(2);
            AssertHasVertices(graph, new[] { 1, 3, 4 });
            AssertHasVertices(cluster1, new[] { 1 });
            AssertHasVertices(cluster2, new[] { 1, 4 });
            AssertNoVertex(cluster3);

            graph.RemoveVertex(1);
            AssertHasVertices(graph, new[] { 3, 4 });
            AssertNoVertex(cluster1);
            AssertHasVertices(cluster2, new[] { 4 });
            AssertNoVertex(cluster3);

            graph.RemoveVertex(3);
            AssertHasVertices(graph, new[] { 4 });
            AssertNoVertex(cluster1);
            AssertHasVertices(cluster2, new[] { 4 });
            AssertNoVertex(cluster3);

            graph.RemoveVertex(4);
            AssertNoVertex(graph);
            AssertNoVertex(cluster1);
            AssertNoVertex(cluster2);
            AssertNoVertex(cluster3);
        }