Beispiel #1
0
        public void TreeEntityExtensions_GetPrefixTree()
        {
            TestTree tree  = new TestTree();
            TreeNode node1 = new TreeNode();

            tree.SetRootNode(node1);

            TreeNode node2 = new TreeNode();
            TreeNode node3 = new TreeNode();

            node1.AppendChild(node2);
            node1.AppendChild(node3);

            TreeNode node4 = new TreeNode();

            node2.AppendChild(node4);
            TreeNode node5 = new TreeNode();
            TreeNode node6 = new TreeNode();

            node3.AppendChild(node5);
            node3.AppendChild(node6);

            List <TreeNode> list = TreeEntityExtensions.GetPrefixTree(tree).ToList();

            Assert.Equal(new TreeNode[]
            {
                node1,
                node2,
                node4,
                node3,
                node5,
                node6
            }, list);
        }
Beispiel #2
0
        public void TreeEntityExtensions_GetSize()
        {
            TestTree tree  = new TestTree();
            TreeNode node1 = new TreeNode();

            tree.SetRootNode(node1);

            TreeNode node2 = new TreeNode();
            TreeNode node3 = new TreeNode();

            node1.AppendChild(node2);
            node1.AppendChild(node3);

            TreeNode node4 = new TreeNode();

            node2.AppendChild(node4);
            TreeNode node5 = new TreeNode();
            TreeNode node6 = new TreeNode();

            node3.AppendChild(node5);
            node3.AppendChild(node6);

            int size = TreeEntityExtensions.GetSize(tree);

            Assert.Equal(6, size);
        }
Beispiel #3
0
        private static TestTree CreateTree2()
        {
            TestTree tree  = new TestTree();
            TreeNode node1 = new TreeNode();

            tree.SetRootNode(node1);

            TreeNode node2 = new TreeNode();
            TreeNode node3 = new TreeNode();
            TreeNode node4 = new TreeNode();

            node1.AppendChild(node2);
            node1.AppendChild(node3);
            node1.AppendChild(node4);

            TreeNode node5 = new TreeNode();
            TreeNode node6 = new TreeNode();

            node2.AppendChild(node5);
            node4.AppendChild(node6);
            return(tree);
        }
Beispiel #4
0
        public void TreeHelper_Swap()
        {
            TestTree entity1 = new TestTree();
            TreeNode node1   = new TreeNode();

            entity1.SetRootNode(node1);
            TreeNode childNode1      = new TreeNode();
            TreeNode grandChildNode1 = new TreeNode();

            node1.AppendChild(childNode1);
            childNode1.AppendChild(grandChildNode1);

            TestTree entity2 = new TestTree();
            TreeNode node2   = new TreeNode();

            entity2.SetRootNode(node2);
            TreeNode childNode2      = new TreeNode();
            TreeNode grandChildNode2 = new TreeNode();

            node2.AppendChild(childNode2);
            childNode2.AppendChild(grandChildNode2);

            TreeHelper.Swap(entity1.RootNode, entity2.RootNode.ChildNodes[0]);

            Assert.Same(childNode2, entity1.RootNode);
            Assert.Null(childNode2.ParentNode);
            Assert.Same(entity1, childNode2.Tree);
            Assert.Same(entity1, grandChildNode2.Tree);

            Assert.Same(node2, entity2.RootNode);
            Assert.Same(node1, entity2.RootNode.ChildNodes[0]);
            Assert.Same(node2, node1.ParentNode);
            Assert.Same(entity2, node1.Tree);
            Assert.Same(entity2, childNode1.Tree);
            Assert.Same(entity2, grandChildNode1.Tree);
        }