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); } } }
public void MinimalTreeTest() { for (int i = 0; i < 10; i++) { int minHeight = 0; for (int j = 0; j <= 20; j++) { if (j == 1 << minHeight) { minHeight++; } int[] data = ArrayUtilities.CreateRandomArray(j, 0, 10); BinaryTreeNode <int> root = MinimalTree.Recursive(data); Assert.AreEqual(BinaryTreeUtilities.Height(root), minHeight); } } }
public void LargestElementsTest() { Func <BinaryTreeNode <int>, int, int[]>[] functions = new Func <BinaryTreeNode <int>, int, int[]>[] { LargestElements.BruteForce, LargestElements.ReverseOrder }; for (int i = 0; i < 10; i++) { BinaryTreeNode <int> root = BinaryTreeUtilities.CreateRandomBinaryTree(10, 0, 15); int[][] results = new int[functions.Length][]; for (int k = 0; k <= 10; k++) { Tests.TestFunctions(root, k, functions); } } }
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); } } }