Exemplo n.º 1
0
        public void Should_DepthFirstSearch_Throw_If_Out_Of_Range_Index()
        {
            //arrange
            var graph = new MyGraphAdj <int>(5);

            //act
            Action actLower  = () => graph.DepthFirstSearch(-1).ToArray();
            Action actHigher = () => graph.DepthFirstSearch(6).ToArray();

            //assert
            actLower.ShouldThrow <ArgumentOutOfRangeException>();
            actHigher.ShouldThrow <ArgumentOutOfRangeException>();

            graph.Capacity.ShouldBeEquivalentTo(5);
            graph.Count.ShouldBeEquivalentTo(0);
        }
Exemplo n.º 2
0
        public void Should_DepthFirstSearch_Throw_If_Node_Is_Null()
        {
            //arrange
            var graph = new MyGraphAdj <int>(5);

            //act
            Action act = () => graph.DepthFirstSearch(1).ToArray();

            //assert
            act.ShouldThrow <ArgumentException>();

            graph.Capacity.ShouldBeEquivalentTo(5);
            graph.Count.ShouldBeEquivalentTo(0);
        }
Exemplo n.º 3
0
        public void Should_DepthFirstSearch_Length_One()
        {
            //arrange
            var graph = new MyGraphAdj <int>(6);

            graph.AddVertex(0, 0);

            //act
            var result = graph.DepthFirstSearch(0).ToArray();

            //assert
            result.Length.ShouldBeEquivalentTo(1);
            result[0].ShouldBeEquivalentTo(0);

            graph.Capacity.ShouldBeEquivalentTo(6);
            graph.Count.ShouldBeEquivalentTo(1);
        }
Exemplo n.º 4
0
        public void Should_DepthFirstSearch_With_Weighted_Edges()
        {
            //arrange
            var graph = new MyGraphAdj <int>(6, true);

            graph.AddVertex(0, 0);
            graph.AddVertex(1, 1);
            graph.AddVertex(2, 2);
            graph.AddVertex(3, 3);
            graph.AddVertex(4, 4);
            graph.AddVertex(5, 5);

            graph.AddEdge(0, 5, 1);
            graph.AddEdge(0, 1, 2);
            graph.AddEdge(0, 4, 3);
            graph.AddEdge(1, 3, 4);
            graph.AddEdge(1, 4, 5);
            graph.AddEdge(2, 1, 6);
            graph.AddEdge(3, 2, 7);
            graph.AddEdge(3, 4, 8);

            var resDfs = new[] { 0, 5, 4, 1, 3, 2 };

            //act
            var result = graph.DepthFirstSearch(0).ToArray();

            //assert
            result.Length.ShouldBeEquivalentTo(resDfs.Length);
            for (int i = 0; i < result.Length; i++)
            {
                result[i].ShouldBeEquivalentTo(resDfs[i]);
            }

            graph.Capacity.ShouldBeEquivalentTo(6);
            graph.Count.ShouldBeEquivalentTo(6);
        }