示例#1
0
        public void SimpleCycle()
        {
            var    graph = new MutableDirectedGraph();
            NodeId a     = graph.CreateNode();
            NodeId b     = graph.CreateNode();
            NodeId c     = graph.CreateNode();
            NodeId d     = graph.CreateNode();
            NodeId e     = graph.CreateNode();
            NodeId f     = graph.CreateNode();

            graph.AddEdge(a, b);
            graph.AddEdge(b, c);
            graph.AddEdge(c, b); // Cycle-forming backedge (violates topo order).
            graph.AddEdge(d, e);
            graph.AddEdge(e, f);

            XAssert.IsTrue(graph.IsReachableFrom(a, b), "Shouldn't visit the backedge");
            XAssert.IsTrue(graph.IsReachableFrom(a, c), "Shouldn't visit the backedge");

            try
            {
                // Note that to fail, we need a > e here due to a fast-path for 'unreachable'
                // that doesn't look at any edges.
                graph.IsReachableFrom(a, f); // Fails since it should find the backedge c -> b
            }
            catch (BuildXLException)
            {
                return;
            }

            XAssert.Fail("Expected a failure due to a topological order violation");
        }
示例#2
0
        public void DisconnectedNodes()
        {
            var    graph = new MutableDirectedGraph();
            NodeId a     = graph.CreateNode();
            NodeId b     = graph.CreateNode();

            XAssert.IsFalse(graph.IsReachableFrom(a, b));
            XAssert.IsFalse(graph.IsReachableFrom(b, a));
        }
示例#3
0
        public void TriviallyConnectedNodes()
        {
            var    graph = new MutableDirectedGraph();
            NodeId a     = graph.CreateNode();
            NodeId b     = graph.CreateNode();

            graph.AddEdge(a, b);

            XAssert.IsTrue(graph.IsReachableFrom(a, b));
            XAssert.IsFalse(graph.IsReachableFrom(b, a));
        }
示例#4
0
        public void TopologicalOrderViolationsIgnoredIfRequested()
        {
            var    graph = new MutableDirectedGraph();
            NodeId a     = graph.CreateNode();
            NodeId b     = graph.CreateNode();
            NodeId c     = graph.CreateNode();
            NodeId d     = graph.CreateNode();

            graph.AddEdge(a, b);
            graph.AddEdge(d, c); // This edge breaks the topological labelling.

            XAssert.IsFalse(graph.IsReachableFrom(a, c, skipOutOfOrderNodes: true));
        }
示例#5
0
        public void MultipleLevels()
        {
            var graph = new MutableDirectedGraph();

            NodeId l0 = graph.CreateNode();

            NodeId l1_n1 = graph.CreateNode();
            NodeId l1_n2 = graph.CreateNode();

            graph.AddEdge(l0, l1_n1);
            graph.AddEdge(l0, l1_n2);
            graph.AddEdge(l1_n1, l1_n2);

            NodeId l2_n1 = graph.CreateNode();
            NodeId l2_n2 = graph.CreateNode();

            graph.AddEdge(l1_n1, l2_n1);
            graph.AddEdge(l1_n2, l2_n2);

            NodeId l3_n1 = graph.CreateNode();
            NodeId l3_n2 = graph.CreateNode();

            graph.AddEdge(l2_n1, l3_n1);
            graph.AddEdge(l2_n2, l3_n2);

            NodeId l4 = graph.CreateNode();

            graph.AddEdge(l3_n1, l4);
            graph.AddEdge(l3_n2, l4);

            XAssert.IsTrue(graph.IsReachableFrom(l1_n1, l3_n2));
            XAssert.IsTrue(graph.IsReachableFrom(l0, l4));

            XAssert.IsFalse(graph.IsReachableFrom(l3_n2, l1_n1));
            XAssert.IsFalse(graph.IsReachableFrom(l4, l0));
        }
示例#6
0
        public void TrivialViolationOfTopologicalOrder()
        {
            var    graph = new MutableDirectedGraph();
            NodeId a     = graph.CreateNode();
            NodeId b     = graph.CreateNode();
            NodeId c     = graph.CreateNode();
            NodeId d     = graph.CreateNode();

            graph.AddEdge(a, b);
            graph.AddEdge(d, c); // This edge breaks the topological labelling.

            try
            {
                // Note that to fail, we need c > a here due to a fast-path for 'unreachable'
                // that doesn't look at any edges.
                graph.IsReachableFrom(a, c);
            }
            catch (BuildXLException)
            {
                return;
            }

            XAssert.Fail("Expected a failure due to a topological order violation");
        }