/// <summary> /// Checks whether the tree is a proper binary search tree. /// </summary> /// <param name="tree">A binary search tree. </param> /// <param name="root">The root node of the tree. </param> /// <param name="expectedTotalKeyCount">Expected total number of keys in the tree. </param> public void HasBinarySearchTreeProperties(BinarySearchTreeBase <int, string> tree, BinarySearchTreeNode <int, string> root, int expectedTotalKeyCount) { Assert.IsTrue(BinarySearchTreeBaseTests.HasBinarySearchTreeOrderProperty <BinarySearchTreeNode <int, string>, int, string>(root)); var inOrderTraversal = new List <BinarySearchTreeNode <int, string> >(); tree.InOrderTraversal(root, inOrderTraversal); Assert.AreEqual(expectedTotalKeyCount, inOrderTraversal.Count); for (int i = 0; i < inOrderTraversal.Count - 1; i++) { Assert.IsTrue(inOrderTraversal[i].Key < inOrderTraversal[i + 1].Key); } }
public void Initialize() { _tree = new BinarySearchTreeBase <int, string>(); _root = _tree.Build(Constants.KeyValues); }