コード例 #1
0
        public void SatisfiesBSTTest()
        {
            Func <BinaryTreeNode <int>, bool>[] functions = new Func <BinaryTreeNode <int>, bool>[]
            {
                SatisfiesBST.BruteForce,
                SatisfiesBST.Recursive,
                SatisfiesBST.InOrderTraversal,
                SatisfiesBST.Queue
            };

            for (int i = 0; i < 10; i++)
            {
                int[] data = ArrayUtilities.CreateRandomArray(10, 0, 20);

                BinaryTreeNode <int> root = new BinaryTreeNode <int>(data[0]);

                for (int j = 1; j < data.Length; j++)
                {
                    BinarySearchTree.Insert(root, data[j]);
                    Tests.TestFunctions(root, functions);
                }

                root = new BinaryTreeNode <int>(data[0]);

                for (int j = 1; j < data.Length; j++)
                {
                    BinaryTreeUtilities.AddRandomNode(root, data[j]);
                    Tests.TestFunctions(root, functions);
                }
            }
        }
コード例 #2
0
        public void IsHeightBalancedTest()
        {
            Func <BinaryTreeNode <int>, bool>[] functions = new Func <BinaryTreeNode <int>, bool>[]
            {
                IsHeightBalanced.BruteForce,
                IsHeightBalanced.Recursive,
            };

            for (int i = 0; i < 10; i++)
            {
                BinaryTreeNode <int> root = new BinaryTreeNode <int>();

                for (int j = 0; j < 20; j++)
                {
                    BinaryTreeUtilities.AddRandomNode(root, 0);
                    Tests.TestFunctions(root, functions);
                }
            }
        }