public void Should_Remove_With_Right_Right_Rebalance() { //arrange var tree = new MyAVLTree <int>(); tree.Insert(5); tree.Insert(2); tree.Insert(7); tree.Insert(1); tree.Insert(4); tree.Insert(6); tree.Insert(15); tree.Insert(3); tree.Insert(9); tree.Insert(16); //act tree.Remove(9); tree.Remove(6); //assert tree.Count.ShouldBeEquivalentTo(8); tree.Root.Data.ShouldBeEquivalentTo(5); tree.Root.TreeHeight.ShouldBeEquivalentTo(4); tree.Root.Left.Data.ShouldBeEquivalentTo(2); tree.Root.Left.TreeHeight.ShouldBeEquivalentTo(3); tree.Root.Right.Data.ShouldBeEquivalentTo(15); tree.Root.Right.TreeHeight.ShouldBeEquivalentTo(2); tree.Root.Left.Left.Data.ShouldBeEquivalentTo(1); tree.Root.Left.Left.TreeHeight.ShouldBeEquivalentTo(1); tree.Root.Left.Right.Data.ShouldBeEquivalentTo(4); tree.Root.Left.Right.TreeHeight.ShouldBeEquivalentTo(2); tree.Root.Right.Left.Data.ShouldBeEquivalentTo(7); tree.Root.Right.Left.TreeHeight.ShouldBeEquivalentTo(1); tree.Root.Right.Right.Data.ShouldBeEquivalentTo(16); tree.Root.Right.Right.TreeHeight.ShouldBeEquivalentTo(1); tree.Root.Left.Right.Left.Data.ShouldBeEquivalentTo(3); tree.Root.Left.Right.Left.TreeHeight.ShouldBeEquivalentTo(1); }
public void Should_Check_Remove_Example() { //arrange var tree = new MyAVLTree <int>(); tree.Insert(44); tree.Insert(17); tree.Insert(62); tree.Insert(32); tree.Insert(50); tree.Insert(78); tree.Insert(48); tree.Insert(54); tree.Insert(88); //act tree.Remove(32); //assert tree.Count.ShouldBeEquivalentTo(8); tree.Root.Data.ShouldBeEquivalentTo(62); tree.Root.TreeHeight.ShouldBeEquivalentTo(4); tree.Root.Left.Data.ShouldBeEquivalentTo(44); tree.Root.Left.TreeHeight.ShouldBeEquivalentTo(3); tree.Root.Right.Data.ShouldBeEquivalentTo(78); tree.Root.Right.TreeHeight.ShouldBeEquivalentTo(2); tree.Root.Left.Left.Data.ShouldBeEquivalentTo(17); tree.Root.Left.Left.TreeHeight.ShouldBeEquivalentTo(1); tree.Root.Left.Right.Data.ShouldBeEquivalentTo(50); tree.Root.Left.Right.TreeHeight.ShouldBeEquivalentTo(2); tree.Root.Right.Right.Data.ShouldBeEquivalentTo(88); tree.Root.Right.Right.TreeHeight.ShouldBeEquivalentTo(1); tree.Root.Left.Right.Left.Data.ShouldBeEquivalentTo(48); tree.Root.Left.Right.Left.TreeHeight.ShouldBeEquivalentTo(1); tree.Root.Left.Right.Right.Data.ShouldBeEquivalentTo(54); tree.Root.Left.Right.Right.TreeHeight.ShouldBeEquivalentTo(1); }