Example #1
0
        private static void ValidateNode(BinaryTreeNode <int> node, int min = int.MinValue, int max = int.MaxValue)
        {
            if (node == null)
            {
                return;
            }

            Assert.IsTrue(node.Data >= min);
            Assert.IsTrue(node.Data <= max);

            BinarySearchTreeTests.ValidateNode(node.Left, min, node.Data);
            BinarySearchTreeTests.ValidateNode(node.Right, node.Data, max);
        }
Example #2
0
        private static void ValidateTree(BinaryTreeNode <int> root, int[] data, int count)
        {
            BinarySearchTreeTests.ValidateNode(root);
            int[] sorted = new int[count];
            Array.Copy(data, sorted, count);
            Array.Sort(sorted);

            foreach (int x in sorted)
            {
                Assert.IsNotNull(BinarySearchTree.Find(root, x));
            }

            int l = 0;

            foreach (BinaryTreeNode <int> x in BinaryTree.InOrderTraversal(root))
            {
                Assert.AreEqual(x.Data, sorted[l]);
                l++;
            }

            Assert.AreEqual(l, count);
        }