예제 #1
0
        private void TestInternal(ControlFlowGraph graph,
                                  DominatorDictionary expectedDoms,
                                  ParentsDictionary expectedParents,
                                  ChildrenDictionary expectedChildren)
        {
            var dt         = new DominatorTree();
            var dominators = dt.GetDominators(graph);
            var tree       = dt.Execute(graph);
            var blocks     = graph.GetCurrentBasicBlocks();

            Assert.AreEqual(blocks.Count, dominators.Count(), "Dominators count and blocks count are different");

            for (var i = 0; i < blocks.Count(); ++i)
            {
                CollectionAssert.AreEquivalent(expectedDoms[i], dominators[blocks[i]], $"Check dominators: error for block #{i}");
            }

            for (var i = 0; i < blocks.Count(); ++i)
            {
                Assert.AreEqual(expectedParents[i], tree.Parent(blocks[i]), $"Check parents: error for block #{i}");
                CollectionAssert.AreEquivalent(expectedChildren[i], tree.Children(blocks[i]), $"Check children: error for block #{i}");
            }
        }