public void Test_Add_Then_Verify_Properties() { // 30 // / \ // 20 40 // / \ // 10 50 // / / \ // 5 ->45 60 // / \ // 3 70 // \ / // 4 65 IBinarySearchTree <byte> bt = this.CreateFullBinaryTree(); bt.Add(45); BT.Node <byte>?node = bt.Get(45); Assert.False(bt.IsEmpty); Assert.NotNull(node); Assert.NotNull(node !.Parent); Assert.NotNull(node !.Parent !.Right); Assert.Equal(50, node.Parent !.Value); Assert.Null(node.Left); Assert.Null(node.Right); }
public void Test_Get() { IBinarySearchTree <byte> bt = this.CreateFullBinaryTree(); BT.Node <byte> node = bt.Get(3) !; Assert.Equal(3, node.Value); Assert.NotNull(node.Parent); Assert.Null(node.Left); Assert.NotNull(node.Right); Assert.Equal(4, node.Right !.Value); }
public void Test_Delete_Then_Verify_Properties() { // 10 10 // / \ / \ // 4 50 4 50 // / \ / \ => / \ / \ // 3 5 30 65 3 5 30 65 // / \ / \ / \ / \ // 20 40 60 70 20 40 60 70 IBinarySearchTree <byte> bt = this.CreateFullBinaryTree(); bt.Delete(60); bt.Delete(70); BT.Node <byte> node = bt.Get(65) !; Assert.False(bt.IsEmpty); Assert.NotNull(node.Parent); Assert.Equal(50, node.Parent !.Value); Assert.Null(node.Left !); Assert.Null(node.Right !); }
public void Test_Add_Then_Verify_Properties() { // 10 10 // / \ / \ // 4 50 4 50 // / \ / \ => / \ / \ // 3 5 30 65 3 5 30 70 // / \ / \ / / \ / \ // 20 40 60 70 2 20 40 65 70 IBinarySearchTree <byte> bt = this.CreateFullBinaryTree(); bt.Add(2); BT.Node <byte> node = bt.Get(2) !; Assert.False(bt.IsEmpty); Assert.NotNull(node.Parent); Assert.NotNull(node.Parent !.Left); Assert.Null(node.Left); Assert.Null(node.Right); Assert.Equal(3, node.Parent !.Value); }
public void Test_Delete_Then_Verify_Properties() { // ->30 40 // / \ / \ // 20 40 20 50 // / \ / \ // 10 50 => 10 60 // / \ / \ // 5 60 5 70 // / \ / / // 3 70 3 65 // \ / \ // 4 65 4 IBinarySearchTree <byte> bt = this.CreateFullBinaryTree(); bt.Delete(30); BT.Node <byte> node = bt.Get(40) !; Assert.Null(node.Parent); Assert.Equal(20, node.Left !.Value); Assert.Equal(50, node.Right !.Value); }
public void Test_Get_When_NotFound() { IBinarySearchTree <byte> bt = this.CreateFullBinaryTree(); Assert.Null(bt.Get(255)); }
public void Test_Get_Throws_InvalidOperation_When_Empty() { IBinarySearchTree <byte> bt = this.CreateInstance(); Assert.Throws <InvalidOperationException>(() => bt.Get(10)); }