Ejemplo n.º 1
0
        public void Should_Throw_Update_Edge_If_vertexes_Does_Not_Exists()
        {
            //arrange
            var graph = new MyGraphAdj <int>(6);

            //act
            Action act = () => graph.UpdateWeight(0, 1, 2);

            //assert
            act.ShouldThrow <InvalidOperationException>();
        }
Ejemplo n.º 2
0
        public void Should_Throw_Update_Edge_If_It_Was_Not_Added()
        {
            //arrange
            var graph = new MyGraphAdj <int>(6, true);

            graph.AddVertex(0, 0);
            graph.AddVertex(1, 1);

            //act
            Action act = () => graph.UpdateWeight(0, 1, 2);

            //assert
            act.ShouldThrow <ArgumentException>();
        }
Ejemplo n.º 3
0
        public void Should_Throw_Update_Edge_With_Weight_If_Not_Weighted_Graph()
        {
            //arrange
            var graph = new MyGraphAdj <int>(6);

            graph.AddVertex(0, 0);
            graph.AddVertex(1, 1);


            //act
            Action act = () => graph.UpdateWeight(0, 1, 5);

            //assert
            act.ShouldThrow <InvalidOperationException>();
        }
Ejemplo n.º 4
0
        public void Should_Throw_Update_Edge_If_Node_From_Equals_Node_To()
        {
            //arrange
            var graph = new MyGraphAdj <int>(6, true);

            graph.AddVertex(0, 0);
            graph.AddVertex(1, 1);
            graph.AddEdge(0, 1, 5);

            //act
            Action act = () => graph.UpdateWeight(0, 0, 7);

            //assert
            act.ShouldThrow <ArgumentOutOfRangeException>();
        }
Ejemplo n.º 5
0
        private void UpdateWeights(MyGraphAdj <T> tempGraph, IEnumerable <int> newWeights)
        {
            List <int[]> edgesToDelete = tempGraph.GetAllEdges().Where(x => x[2] == 0).ToList();

            foreach (var edge in edgesToDelete)
            {
                tempGraph.RemoveEdge(edge[0], edge[1]);
            }

            tempGraph.Remove((tempGraph.GetAllVertexes().Last().Key));

            var restEdges = tempGraph.GetAllEdges();

            foreach (var edge in restEdges)
            {
                int newWeight = edge[2] + newWeights.ElementAt(edge[0]) - newWeights.ElementAt(edge[1]);
                tempGraph.UpdateWeight(edge[0], edge[1], newWeight);
            }
        }
Ejemplo n.º 6
0
        public void Should_Update_Edge_Weight()
        {
            //arrange
            var graph = new MyGraphAdj <int>(6, true);

            graph.AddVertex(0, 0);
            graph.AddVertex(1, 1);
            graph.AddEdge(0, 1, 5);

            //act
            graph.UpdateWeight(0, 1, 7);
            var result = graph.GetAllEdges().ToList();

            //assert
            result.Count.ShouldBeEquivalentTo(1);
            result[0][0].ShouldBeEquivalentTo(0);
            result[0][1].ShouldBeEquivalentTo(1);
            result[0][2].ShouldBeEquivalentTo(7);
        }
Ejemplo n.º 7
0
        public void Should_Throw_Update_Edge_If_Index_Out_Of_Range()
        {
            //arrange
            var graph = new MyGraphAdj <int>(6, true);

            graph.AddVertex(0, 0);
            graph.AddVertex(1, 1);
            graph.AddEdge(0, 1, 1);

            //act
            Action actLowerFrom  = () => graph.UpdateWeight(-1, 1, 2);
            Action actLowerTo    = () => graph.AddEdge(0, -1, 2);
            Action actHigherFrom = () => graph.AddEdge(10, 1, 2);
            Action actHigherTo   = () => graph.AddEdge(0, 10, 2);

            //assert
            actLowerFrom.ShouldThrow <ArgumentOutOfRangeException>();
            actLowerTo.ShouldThrow <ArgumentOutOfRangeException>();
            actHigherFrom.ShouldThrow <ArgumentOutOfRangeException>();
            actHigherTo.ShouldThrow <ArgumentOutOfRangeException>();
        }