Delete the root element from the tree. · initialcommit-io/tutorials@76d17d7 · GitHub
Skip to content

Commit 76d17d7

Browse files
author
Imre Balassa
committed
Delete the root element from the tree.
1 parent b4969dd commit 76d17d7

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎data-structures/src/main/java/com/baeldung/tree/BinaryTree.java‎

Lines changed: 1 addition & 1 deletion

data-structures/src/test/java/com/baeldung/tree/BinaryTreeTest.java renamed to data-structures/src/test/java/com/baeldung/tree/BinaryTreeUnitTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import org.junit.Test;
88

9-
public class BinaryTreeTest {
9+
public class BinaryTreeUnitTest {
1010

1111
@Test
1212
public void givenABinaryTree_WhenAddingElements_ThenTreeNotEmpty() {
@@ -70,6 +70,17 @@ public void givenABinaryTree_WhenDeletingNonExistingElement_ThenTreeDoesNotDelet
7070
assertEquals(initialSize, bt.getSize());
7171
}
7272

73+
@Test
74+
public void it_deletes_the_root() {
75+
int value = 12;
76+
BinaryTree bt = new BinaryTree();
77+
bt.add(value);
78+
79+
assertTrue(bt.containsNode(value));
80+
bt.delete(value);
81+
assertFalse(bt.containsNode(value));
82+
}
83+
7384
@Test
7485
public void givenABinaryTree_WhenTraversingInOrder_ThenPrintValues() {
7586

data-structures/src/test/java/com/baeldung/trie/TrieTest.java renamed to data-structures/src/test/java/com/baeldung/trie/TrieUnitTest.java

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)