public void RotateLeftRotatesRootNode() { PointerBackedBinaryTree <int> testTree = new PointerBackedBinaryTree <int>(); testTree.Root = new PointerBackedBinaryTreeNode <int>(1, null); testTree.Root.Right = new PointerBackedBinaryTreeNode <int>(2, testTree.Root); testTree.RotateLeft(testTree.Root); // Validate the entire tree structure after rotation, including internal pointers. Assert.AreEqual(2, testTree.Root.Data); Assert.IsNull(testTree.Root.Parent); Assert.IsNull(testTree.Root.Right); Assert.AreEqual(1, testTree.Root.Left.Data); Assert.AreEqual(testTree.Root, testTree.Root.Left.Parent); Assert.IsNull(testTree.Root.Left.Right); Assert.IsNull(testTree.Root.Left.Left); }
public void RotateLeftRotatesNode() { PointerBackedBinaryTree <int> testTree = new PointerBackedBinaryTree <int>(); testTree.Root = new PointerBackedBinaryTreeNode <int>(1, null); testTree.Root.Right = new PointerBackedBinaryTreeNode <int>(2, testTree.Root); testTree.Root.Right.Left = new PointerBackedBinaryTreeNode <int>(3, testTree.Root.Right); testTree.Root.Right.Right = new PointerBackedBinaryTreeNode <int>(4, testTree.Root.Right); testTree.Root.Right.Right.Left = new PointerBackedBinaryTreeNode <int>(5, testTree.Root.Right.Right); testTree.Root.Right.Right.Right = new PointerBackedBinaryTreeNode <int>(6, testTree.Root.Right.Right); testTree.RotateLeft(testTree.Root.Right); // Validate the tree structure Assert.AreEqual(1, testTree.Root.Data); Assert.AreEqual(4, testTree.Root.Right.Data); Assert.AreEqual(2, testTree.Root.Right.Left.Data); Assert.AreEqual(6, testTree.Root.Right.Right.Data); Assert.AreEqual(3, testTree.Root.Right.Left.Left.Data); Assert.AreEqual(5, testTree.Root.Right.Left.Right.Data); }