示例#1
0
        public void DFS()
        {
            var service = new OrientedGrapthService(4);

            service.AddEdge(2, 0);
            service.AddEdge(0, 2);
            service.AddEdge(1, 2);
            service.AddEdge(0, 1);
            service.AddEdge(3, 3);
            service.AddEdge(1, 3);
            var expectedTraversal = new List <int>(new int[] { 2, 0, 1, 3 });

            var result = service.DepthFirstSearch(2);

            Assert.AreEqual(expectedTraversal, result);
        }
示例#2
0
        public void AreConnected_FalseCase()
        {
            var service = new OrientedGrapthService(4);

            service.AddEdge(2, 0);
            service.AddEdge(0, 2);
            service.AddEdge(1, 2);
            service.AddEdge(0, 1);
            service.AddEdge(3, 3);

            var result = service.AreConnected(2, 3);

            Assert.False(result);

            result = service.AreConnectedOptimized(2, 3);
            Assert.False(result);
        }