Пример #1
0
        public static void TestDeleteLeafFromTree()
        {
            var root  = new SimpleTreeNode <int>(1, null);
            var tree  = new SimpleTree <int>(root);
            var node2 = new SimpleTreeNode <int>(2, root);

            tree.AddChild(root, node2);
            var node3 = new SimpleTreeNode <int>(3, root);

            tree.AddChild(root, node3);
            var node4 = new SimpleTreeNode <int>(4, node3);

            tree.AddChild(node3, node4);
            var count     = tree.Count();
            var leafCount = tree.LeafCount();

            Assert.AreEqual(4, count);
            Assert.AreEqual(2, leafCount);

            tree.DeleteNode(node4);

            count     = tree.Count();
            leafCount = tree.LeafCount();
            Assert.AreEqual(3, count);
            Assert.AreEqual(2, leafCount);

            Assert.AreEqual(true, root.Children.Contains(node2));
            Assert.AreEqual(true, root.Children.Contains(node3));
            Assert.IsNull(node3.Children);
        }
Пример #2
0
        public void FindAfterDelete()
        {
            var root  = new SimpleTreeNode <int>(0, null);
            var node1 = new SimpleTreeNode <int>(1, null);
            var node2 = new SimpleTreeNode <int>(2, null);
            var node3 = new SimpleTreeNode <int>(3, null);
            var node4 = new SimpleTreeNode <int>(4, null);
            var node5 = new SimpleTreeNode <int>(5, null);

            var tree = new SimpleTree <int>(root);

            tree.AddChild(root, node1);
            tree.AddChild(root, node2);
            tree.AddChild(root, node3);
            tree.AddChild(node3, node4);
            tree.AddChild(node3, node5);

            Assert.True(tree.FindNodesByValue(5).Count == 1);

            tree.DeleteNode(node5);
            tree.DeleteNode(node2);

            Assert.True(tree.Count() == 4);
            Assert.True(tree.FindNodesByValue(5).Count == 0);
            Assert.True(tree.GetAllNodes().Count == 4);
            Assert.True(tree.LeafCount() == 2);
        }
        public void SimpleTreeTest()
        {
            SimpleTreeNode <string> a1   = new SimpleTreeNode <string>("a", null);
            SimpleTree <string>     tree = new SimpleTree <string>(a1);

            tree.MoveNode(a1, a1);
            List <SimpleTreeNode <string> > aa = tree.GetAllNodes();
            int aaa = tree.Count();

            if (aaa != 1)
            {
                Assert.Fail();
            }
            int AA = tree.LeafCount();

            if (AA != 1)
            {
                Assert.Fail();
            }
            tree.DeleteNode(a1);
            int BB = tree.LeafCount();

            if (BB != 1)
            {
                Assert.Fail();
            }
            int bbb = tree.Count();

            if (bbb != 1)
            {
                Assert.Fail();
            }
            List <SimpleTreeNode <string> > aaaaaa = tree.FindNodesByValue("a");

            if (aaaaaa.Count != 1)
            {
                Assert.Fail();
            }
            List <SimpleTreeNode <string> > ab = tree.GetAllNodes();

            if (ab.Count != 1)
            {
                Assert.Fail();
            }
        }
Пример #4
0
        public void TestCount_1()
        {
            SimpleTreeNode <int>[] nodes = GetNodesArray_1();
            SimpleTree <int>       tree  = GetTree(nodes);

            Assert.AreEqual(14, tree.Count());

            tree.MoveNode(nodes[13], nodes[1]);
            tree.MoveNode(nodes[12], nodes[0]);
            Assert.AreEqual(14, tree.Count());

            // Удаляется узел не имеющий дочерних
            tree.DeleteNode(nodes[12]);
            Assert.AreEqual(13, tree.Count());

            // Удаляется узел с тремя дочерними узлами. (До перемещения было два)
            tree.DeleteNode(nodes[1]);
            Assert.AreEqual(9, tree.Count());
        }
Пример #5
0
        public void Create()
        {
            var root = new SimpleTreeNode <int>(1, null);
            var tree = new SimpleTree <int>(root);

            Assert.True(tree.Count() == 1);
            Assert.True(tree.FindNodesByValue(1).Count == 1);
            Assert.True(tree.GetAllNodes().Count == 1);
            Assert.True(tree.LeafCount() == 1);
        }
Пример #6
0
        public static void TestCount()
        {
            var root = new SimpleTreeNode <int>(1, null);
            var tree = new SimpleTree <int>(root);
            var node = new SimpleTreeNode <int>(2, root);

            tree.AddChild(root, node);
            var node3 = new SimpleTreeNode <int>(3, root);

            tree.AddChild(root, node3);
            var node4 = new SimpleTreeNode <int>(4, node3);

            tree.AddChild(node3, node4);

            var count = tree.Count();

            Assert.AreEqual(4, count);
        }
Пример #7
0
        public void MoveBranch()
        {
            var root    = new SimpleTreeNode <int>(0, null);
            var node1   = new SimpleTreeNode <int>(1, null);
            var node2   = new SimpleTreeNode <int>(2, null);
            var node3   = new SimpleTreeNode <int>(3, null);
            var node4   = new SimpleTreeNode <int>(4, null);
            var node5   = new SimpleTreeNode <int>(5, null);
            var node5_2 = new SimpleTreeNode <int>(5, null);

            var tree = new SimpleTree <int>(root);

            tree.AddChild(root, node1);
            tree.AddChild(root, node2);
            tree.AddChild(node2, node3);
            tree.AddChild(node2, node4);

            tree.MoveNode(node2, node1);

            Assert.True(tree.Count() == 5);
            Assert.True(tree.GetAllNodes().Count == 5);
            Assert.True(tree.LeafCount() == 2);
        }
        public void DeleteNodeTest()
        {
            SimpleTreeNode <string> a1   = new SimpleTreeNode <string>("a", null);
            SimpleTreeNode <string> b1   = new SimpleTreeNode <string>("BA", a1);
            SimpleTreeNode <string> b2   = new SimpleTreeNode <string>("BB", a1);
            SimpleTreeNode <string> b3   = new SimpleTreeNode <string>("BC", a1);
            SimpleTreeNode <string> b4   = new SimpleTreeNode <string>("BC", a1);
            SimpleTreeNode <string> c2   = new SimpleTreeNode <string>("CA", null);
            SimpleTree <string>     tree = new SimpleTree <string>(a1);

            tree.AddChild(a1, b1);
            tree.AddChild(a1, b2);
            tree.AddChild(a1, b3);
            tree.AddChild(a1, b4);
            tree.AddChild(b2, c2);
            int A0 = tree.LeafCount();

            if (A0 != 4)
            {
                Assert.Fail();
            }
            int a0 = tree.Count();

            if (a0 != 6)
            {
                Assert.Fail();
            }
            tree.MoveNode(b2, b1);
            List <SimpleTreeNode <string> > aa = tree.GetAllNodes();
            int aaa = tree.Count();

            if (aaa != 6)
            {
                Assert.Fail();
            }
            int AA = tree.LeafCount();

            if (AA != 3)
            {
                Assert.Fail();
            }
            tree.DeleteNode(b2);
            int BB = tree.LeafCount();

            if (BB != 3)
            {
                Assert.Fail();
            }
            int bbb = tree.Count();

            if (bbb != 4)
            {
                Assert.Fail();
            }
            tree.DeleteNode(b3);
            int cc = tree.LeafCount();

            if (cc != 2)
            {
                Assert.Fail();
            }
            int CCC = tree.Count();

            if (CCC != 3)
            {
                Assert.Fail();
            }

            List <SimpleTreeNode <string> > aaaaaa = tree.FindNodesByValue("a");
            List <SimpleTreeNode <string> > ab     = tree.GetAllNodes();
        }
Пример #9
0
        public void CountNull()
        {
            var tree = new SimpleTree <int>(null);

            Assert.True(tree.Count() == 0);
        }