Exemple #1
0
        private void Valid(IGraphInterface graph)
        {
            // Variable
            List <IVertexInterface> vertexList = graph.AllVertices();

            graph.VertexContraction(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexSuppression(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexExpansion(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexSuppression(vertexList.Last());
            vertexList = graph.AllVertices();

            graph.VertexDelete(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexSuppression(vertexList.Last());
            vertexList = graph.AllVertices();

            IVertexInterface v1 = new Vertex("V1");

            graph.VertexAdd(v1);
            vertexList = graph.AllVertices();

            graph.EdgeAdd(new Edge(vertexList.First(), v1));
            vertexList = graph.AllVertices();

            graph.VertexContraction(v1);
            vertexList = graph.AllVertices();

            graph.EdgeSubdivision(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            graph.EdgeAdd(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            graph.EdgeContraction(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            graph.EdgeDelete(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            graph.VertexDelete(vertexList.Skip(1).First());
            vertexList = graph.AllVertices();

            graph.VertexSuppression(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexDelete(vertexList.First());
            vertexList = graph.AllVertices();

            graph.VertexExpansion(vertexList.First());
            vertexList = graph.AllVertices();

            graph.EdgeContraction(new Edge(vertexList.First(), vertexList.Skip(1).First()));
            vertexList = graph.AllVertices();

            IVertexInterface v2 = new Vertex("V2");

            graph.VertexAdd(v2);
            vertexList = graph.AllVertices();

            graph.VertexDelete(vertexList.Skip(1).First());

            graph.VertexAdd(new Vertex("V3"));
        }
Exemple #2
0
        private void Invalid(IGraphInterface graph)
        {
            // Variable
            List <IVertexInterface> vertexList           = graph.AllVertices();
            List <IVertexInterface> vertexNot2DegreeList = new List <IVertexInterface>();

            vertexNot2DegreeList = vertexList.Where(v => graph.CountNeighbours(v) != 2).ToList();
            IEdgeInterface edge = new Edge(vertexList.First(), graph.Neighbours(vertexList.First()).First());

            // Vertex add
            stringBuilder.AppendLine("Vertex add");
            stringBuilder.AppendLine("Vertex exists");
            try { graph.VertexAdd(vertexList.First()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Vertex delete
            stringBuilder.AppendLine("Vertex delete");
            stringBuilder.AppendLine("Vertex doesn't exist");
            try { graph.VertexDelete(new Vertex()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Vertex contract
            stringBuilder.AppendLine("Vertex contract");
            stringBuilder.AppendLine("Vertex doesn't exist");
            try { graph.VertexContraction(new Vertex()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Vertex suppression
            stringBuilder.AppendLine("Vertex suppression");
            stringBuilder.AppendLine("Vertex doesn't exist");
            try { graph.VertexSuppression(new Vertex()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }
            stringBuilder.AppendLine("Invalid vertex degree");
            try { graph.VertexSuppression(vertexNot2DegreeList.First()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Vertex expansion
            stringBuilder.AppendLine("Vertex expansion");
            stringBuilder.AppendLine("Vertex doesn't exist");
            try { graph.VertexExpansion(new Vertex()); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Edge add
            stringBuilder.AppendLine("Edge add");
            stringBuilder.AppendLine("Edge exists");
            try { graph.EdgeAdd(edge); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Edge delete
            stringBuilder.AppendLine("Edge delete");
            stringBuilder.AppendLine("Edge doesn't exist");
            try { graph.EdgeDelete(new Edge(new Vertex(), new Vertex())); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Edge contract
            stringBuilder.AppendLine("Edge contract");
            stringBuilder.AppendLine("Edge doesn't exist");
            try { graph.EdgeContraction(new Edge(new Vertex(), new Vertex())); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }

            // Edge subdivision
            stringBuilder.AppendLine("Edge subdivision");
            stringBuilder.AppendLine("Edge doesn't exist");
            try { graph.EdgeSubdivision(new Edge(new Vertex(), new Vertex())); }
            catch (MyException.GraphException.GraphException e) { stringBuilder.AppendLine(e.Message); }
        }
        private void Valid(IGraphInterface graph)
        {
            // Variable
            List <IVertexInterface> vertexList   = graph.AllVertices();
            IColoredGraphInterface  coloredGraph = graph.GetColoredGraph();

            if (coloredGraph.InitializeColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ColorVertex(vertexList.First(), coloredGraph.GreedyColoring(vertexList.First()));

            if (coloredGraph.InitializeColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ResetColorVertex(vertexList.First());

            coloredGraph.GreedyColoring(vertexList);

            if (!coloredGraph.InitializeColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.DeinitializationColoredGraph();
            if (!coloredGraph.InitializeColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }
            coloredGraph.DeinitializationColoredGraph();

            coloredGraph.ResetColors();
            coloredGraph.ResetColors();

            if (coloredGraph.InitializeColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ColorVertex(vertexList.First(), 1);
            coloredGraph.ColorVertex(vertexList.ElementAt(1), 1);

            if (coloredGraph.CheckValidColor().Count == 0)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ColorVertex(vertexList.First(), 2);

            if (!coloredGraph.IsVertexColored(vertexList.First()))
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (coloredGraph.IsVertexColored(vertexList.ElementAt(2)))
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ResetColorVertex(vertexList.First());

            if (coloredGraph.IsVertexColored(vertexList.First()))
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ResetColorVertex(vertexList.ElementAt(2));

            if (coloredGraph.IsVertexColored(vertexList.ElementAt(2)))
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ColorVertex(vertexList.First(), 1);

            if (coloredGraph.CheckValidColor(vertexList.First()))
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (!coloredGraph.CheckValidColor(vertexList.ElementAt(2)))
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (coloredGraph.GreedyColoring(vertexList.First()) != 2)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (coloredGraph.GetUnColoredVertexList().Count != 4)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (coloredGraph.GetColoredVertexList().Count != 2)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (coloredGraph.GetCountUsedColors() != 1)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.GreedyColoring(vertexList);

            if (coloredGraph.GetCountUsedColors() != 2)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ColorVertex(vertexList.First(), VertexExtended.GetDefaultColor());

            if (coloredGraph.CheckValidColor().Count != 0)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.GreedyColoring(vertexList);
            coloredGraph.InitializeColoredGraph();

            if (!coloredGraph.GetIsInitializedColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            graph.VertexAdd(new Vertex());

            if (coloredGraph.GetIsInitializedColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            vertexList = graph.AllVertices();

            if (vertexList.Last().GetColor() != VertexExtended.GetDefaultColor())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ColorVertex(vertexList.Last(), 2);
            coloredGraph.ColorVertex(vertexList.First(), 2);

            if (coloredGraph.InitializeColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.GreedyColoring(vertexList);

            if (!coloredGraph.InitializeColoredGraph())
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            graph.VertexDelete(vertexList.Last());
            graph.VertexAdd(new Vertex());
            vertexList = graph.AllVertices();

            if (coloredGraph.GetColoredVertexList().Count != 6)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (coloredGraph.GetUnColoredVertexList().Count != 1)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            coloredGraph.ColorVertex(vertexList.Last(), 3);

            if (coloredGraph.GetCountUsedColors() != 3)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            graph.VertexDelete(vertexList.Last());

            if (coloredGraph.GetColoredVertexList().Count != 6)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (coloredGraph.GetUnColoredVertexList().Count != 0)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }

            if (coloredGraph.GetCountUsedColors() != 2)
            {
                throw new MyException.TestsException.SomethingWrongTestException();
            }
        }