public void Should_Check_Remove_Multiple() { //arrange var tree = new MyBinarySearchTree <int>(); tree.Insert(38); tree.Insert(5); tree.Insert(45); tree.Insert(1); tree.Insert(9); tree.Insert(47); tree.Insert(8); tree.Insert(15); tree.Insert(46); tree.Insert(13); //act tree.Remove(9); tree.Remove(5); tree.Remove(15); //assert tree.Count.ShouldBeEquivalentTo(7); tree.Root.Data.ShouldBeEquivalentTo(38); tree.Root.Left.Data.ShouldBeEquivalentTo(1); tree.Root.Right.Data.ShouldBeEquivalentTo(45); tree.Root.Left.Right.Data.ShouldBeEquivalentTo(8); tree.Root.Right.Right.Data.ShouldBeEquivalentTo(47); tree.Root.Left.Right.Right.Data.ShouldBeEquivalentTo(13); tree.Root.Right.Right.Left.Data.ShouldBeEquivalentTo(46); }
public void Should_Check_Remove_Helper_Leaf_Node_Right() { //arrange var tree = new MyBinarySearchTree <int>(); tree.Insert(38); tree.Insert(5); tree.Insert(45); tree.Insert(1); tree.Insert(9); tree.Insert(47); tree.Insert(8); tree.Insert(15); tree.Insert(48); tree.Insert(13); //act tree.Remove(48); //assert tree.Count.ShouldBeEquivalentTo(9); tree.Root.Data.ShouldBeEquivalentTo(38); tree.Root.Left.Data.ShouldBeEquivalentTo(5); tree.Root.Right.Data.ShouldBeEquivalentTo(45); tree.Root.Left.Left.Data.ShouldBeEquivalentTo(1); tree.Root.Left.Right.Data.ShouldBeEquivalentTo(9); tree.Root.Right.Right.Data.ShouldBeEquivalentTo(47); tree.Root.Left.Right.Left.Data.ShouldBeEquivalentTo(8); tree.Root.Left.Right.Right.Data.ShouldBeEquivalentTo(15); tree.Root.Right.Right.Right.ShouldBeEquivalentTo(null); tree.Root.Left.Right.Right.Left.Data.ShouldBeEquivalentTo(13); }
public void Should_Check_Remove_When_Is_Empty() { //arrange var tree = new MyBinarySearchTree <int>(); //act tree.Remove(3); //assert tree.Count.ShouldBeEquivalentTo(0); tree.Root.ShouldBeEquivalentTo(null); }