コード例 #1
0
        public void Test1()
        {
            // Arrange
            var graph = new Graph();

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

            graph.AddDirectedEdge(0, 1);
            graph.AddDirectedEdge(0, 2);

            graph.AddDirectedEdge(1, 2);

            // cycle: 4 - 5 - 6 - 4
            graph.AddDirectedEdge(3, 0);
            graph.AddDirectedEdge(3, 4);

            graph.AddDirectedEdge(4, 5);

            graph.AddDirectedEdge(5, 3);

            // Act
            var hasCycle = DetectCycleProblem.DetectCycle(graph);

            // Assert
            Assert.IsTrue(hasCycle);
        }
コード例 #2
0
        public void Test3()
        {
            // Arrange
            var graph = new Graph();

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

            graph.AddDirectedEdge(1, 0);

            // Act
            var hasCycle = DetectCycleProblem.DetectCycle(graph);

            // Assert
            Assert.IsFalse(hasCycle);
        }