Пример #1
0
        public void TestEdgesInSubgraphs()
        {
            RootGraph graph = Utils.CreateUniqueTestGraph();
            Node      node  = graph.GetOrAddNode("node");
            Edge      edge  = graph.GetOrAddEdge(node, node, "edge 1");

            SubGraph subgraph                = graph.GetOrAddSubgraph("sub graph");
            Node     subnode                 = subgraph.GetOrAddNode("subnode");
            Edge     subedge_between_node    = subgraph.GetOrAddEdge(node, node, "edge 2");
            Edge     subedge_between_subnode = subgraph.GetOrAddEdge(subnode, subnode, "edge 3");
            Edge     edge_between_subnode    = graph.GetOrAddEdge(subnode, subnode, "edge 4");

            Assert.True(graph.Contains(edge));
            Assert.True(graph.Contains(subedge_between_node));
            Assert.True(graph.Contains(subedge_between_subnode));
            Assert.True(graph.Contains(edge_between_subnode));

            Assert.False(subgraph.Contains(edge));
            Assert.True(subgraph.Contains(subedge_between_node));
            Assert.True(subgraph.Contains(subedge_between_subnode));
            Assert.False(subgraph.Contains(edge_between_subnode));

            // Conclusion:
            // Subgraphs can contain edges, independently of their endpoints.
            // This affects enumeration as follows:
            Assert.AreEqual(2, node.EdgesOut(graph).Count());
            Assert.AreEqual(1, node.EdgesOut(subgraph).Count());
            Assert.AreEqual(2, subnode.EdgesOut(graph).Count());
            Assert.AreEqual(1, subnode.EdgesOut(subgraph).Count());
        }
Пример #2
0
        public void TestCreateNestedStructures()
        {
            // Documentation:
            // Subgraphs are an important construct in Cgraph.They are intended for organizing subsets of
            // graph objects and can be used interchangeably with top - level graphs in almost all Cgraph
            // functions.  A subgraph may contain any nodes or edges of its parent. (When an edge is
            // inserted in a subgraph, its nodes are also implicitly inserted if necessary.Similarly,
            // insertion of a node or edge automatically implies insertion in all containing subgraphs up
            // to the root.) Subgraphs of a graph form a hierarchy(a tree).Cgraph has functions to
            // create, search, and iterate over subgraphs.

            // Conclusion: the hierarchical tree structure is maintained in a sane way across all
            // operations we can do w.r.t. subgraphs.


            // If a node is created in a subgraph, it should also be contained in all supergraphs
            RootGraph graph        = Utils.CreateUniqueTestGraph();
            SubGraph  supergraph   = graph.GetOrAddSubgraph("level 1");
            string    subgraphname = "level 2";
            SubGraph  subgraph     = supergraph.GetOrAddSubgraph(subgraphname);
            string    nodename     = "test node";
            Node      node         = subgraph.GetOrAddNode(nodename);

            // Node must be contained in super graph
            Assert.True(node.MyRootGraph.Equals(graph));
            Assert.True(supergraph.Contains(node));
            Assert.True(supergraph.Nodes().Contains(node));
            Assert.NotNull(supergraph.GetNode(nodename));
            // Node must be contained in root graph
            Assert.True(graph.Contains(node));
            Assert.True(graph.Nodes().Contains(node));
            Assert.NotNull(graph.GetNode(nodename));

            // Subgraph must be contained in super graph
            Assert.True(supergraph.Contains(subgraph));
            Assert.True(supergraph.Descendants().Contains(subgraph));
            Assert.NotNull(supergraph.GetSubgraph(subgraphname));
            // Subgraph must be contained in root graph
            Assert.True(graph.Contains(subgraph));
            Assert.True(graph.Descendants().Contains(subgraph));
            // Subgraph cannot be obtained in the following way:
            //graph.GetSubgraph(subgraphname)
            Assert.Null(graph.GetSubgraph(subgraphname));
            // Use a utility function instead:
            Assert.NotNull(graph.GetDescendantByName(subgraphname));
        }
Пример #3
0
        public void TestNodeAndGraphWithSameName()
        {
            RootGraph root = Utils.CreateUniqueTestGraph();
            SubGraph  sub  = root.GetOrAddSubgraph("name");
            Node      node = sub.GetOrAddNode("name");

            Assert.True(root.Contains(sub));
            Assert.True(sub.Contains(node));
        }