Пример #1
0
        public void GetHeightOfTreeTest()
        {
            // crate a tree
            TreeNode <int> root = new TreeNode <int>(3);

            TreesAndGraphs.Insert(root, 2);
            TreesAndGraphs.Insert(root, 1);
            TreesAndGraphs.Insert(root, 5);
            TreesAndGraphs.Insert(root, 4);
            TreesAndGraphs.Insert(root, 6);
            TreesAndGraphs.Insert(root, 7);
            var height = TreesAndGraphs.GetHeightOfTree(root);

            Assert.AreEqual(3, height);

            root = new TreeNode <int>(3);
            TreesAndGraphs.Insert(root, 2);
            TreesAndGraphs.Insert(root, 1);
            TreesAndGraphs.Insert(root, 5);
            TreesAndGraphs.Insert(root, 4);
            TreesAndGraphs.Insert(root, 6);
            TreesAndGraphs.Insert(root, 7);
            TreesAndGraphs.Insert(root, 8);
            TreesAndGraphs.Insert(root, 20);
            TreesAndGraphs.Insert(root, 19);
            TreesAndGraphs.Insert(root, 18);
            TreesAndGraphs.Insert(root, 16);
            TreesAndGraphs.Insert(root, 15);
            TreesAndGraphs.Insert(root, 17);
            height = TreesAndGraphs.GetHeightOfTree(root);
            Assert.AreEqual(9, height);
        }