예제 #1
0
        public void delete_root_without_children()
        {
            Tree tree = new Tree(10);

            tree.Delete(10);

            Assert.Null(tree.Root);
        }
예제 #2
0
        public void delete_nodes_which_have_two_children_nodes()
        {
            Tree tree = new Tree(100);

            tree.Insert(50);
            tree.Insert(150);
            tree.Insert(25);
            tree.Insert(75);
            tree.Insert(125);
            tree.Insert(60);
            tree.Insert(80);
            tree.Insert(200);

            tree.Delete(50);
            tree.Delete(150);

            Assert.Equal(200, tree.Root.Right.Data);
            Assert.Equal(60, tree.Root.Left.Data);
        }
예제 #3
0
        public void delete_root_with_one_child()
        {
            Tree tree = new Tree(10);

            tree.Insert(15);

            tree.Delete(10);

            Assert.Equal(15, tree.Root.Data);
            Assert.Null(tree.Root.Left);
            Assert.Null(tree.Root.Right);
        }
예제 #4
0
        public void delete_leaf_node_on_first_level()
        {
            Tree tree = new Tree(10);

            tree.Insert(5);
            tree.Insert(15);

            tree.Delete(5);

            Assert.Null(tree.Root.Left);
            Assert.NotNull(tree.Root.Right);
        }
예제 #5
0
        public void throws_exception_when_delete_not_existing_node()
        {
            Tree tree = new Tree(10);

            Assert.Throws <InvalidOperationException>(() => tree.Delete(100));
        }