Beispiel #1
0
        public void Should_DepthFirstSearch_Throw_If_Out_Of_Range_Index()
        {
            //arrange
            var graph = new MyGraph <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);
        }
Beispiel #2
0
        public void Should_DepthFirstSearch_Throw_If_Node_Is_Null()
        {
            //arrange
            var graph = new MyGraph <int>(5);

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

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

            graph.Capacity.ShouldBeEquivalentTo(5);
            graph.Count.ShouldBeEquivalentTo(0);
        }
Beispiel #3
0
        public void Should_DepthFirstSearch_Length_One()
        {
            //arrange
            var graph = new MyGraph <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);
        }
Beispiel #4
0
        public void Should_DepthFirstSearch()
        {
            //arrange
            var graph = new MyGraph <int>(6);

            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);
            graph.AddEdge(0, 1);
            graph.AddEdge(0, 4);
            graph.AddEdge(1, 3);
            graph.AddEdge(1, 4);
            graph.AddEdge(2, 1);
            graph.AddEdge(3, 2);
            graph.AddEdge(3, 4);

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

            //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);
        }