Пример #1
0
        public void Path()
        {
            // Artificially construct a path of four nodes in sequential order.
            var graph = TestGraphs.CreatePath();
            var n1    = graph.GetNodeByOffset(0);
            var n2    = graph.GetNodeByOffset(1);
            var n3    = graph.GetNodeByOffset(2);
            var n4    = graph.GetNodeByOffset(3);

            var dominatorTree = DominatorTree <DummyInstruction> .FromGraph(graph);

            Assert.Equal(graph.Entrypoint, dominatorTree.Root.OriginalNode);

            Assert.True(dominatorTree.Dominates(n1, n1));
            Assert.True(dominatorTree.Dominates(n1, n2));
            Assert.True(dominatorTree.Dominates(n1, n3));
            Assert.True(dominatorTree.Dominates(n1, n4));

            Assert.False(dominatorTree.Dominates(n2, n1));
            Assert.True(dominatorTree.Dominates(n2, n2));
            Assert.True(dominatorTree.Dominates(n2, n3));
            Assert.True(dominatorTree.Dominates(n2, n4));

            Assert.False(dominatorTree.Dominates(n3, n1));
            Assert.False(dominatorTree.Dominates(n3, n2));
            Assert.True(dominatorTree.Dominates(n3, n3));
            Assert.True(dominatorTree.Dominates(n3, n4));

            Assert.False(dominatorTree.Dominates(n4, n1));
            Assert.False(dominatorTree.Dominates(n4, n2));
            Assert.False(dominatorTree.Dominates(n4, n3));
            Assert.True(dominatorTree.Dominates(n4, n4));
        }
Пример #2
0
        public void PathReversed()
        {
            // Artificially construct a path of four nodes in sequential order.
            var graph = TestGraphs.CreatePath();

            // Record a depth first traversal.
            var traversal = new DepthFirstTraversal(true);
            var recorder  = new TraversalOrderRecorder(traversal);

            traversal.Run(graph.GetNodeById(4));

            // Traversal should exactly be the path.
            Assert.Equal(new INode[]
            {
                graph.GetNodeById(4),
                graph.GetNodeById(3),
                graph.GetNodeById(2),
                graph.GetNodeById(1),
            }, recorder.GetTraversal());
        }