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)); }