Skip to content

Commit 819f078

Browse files
author
Krishnan M
committed
updated
1 parent 89937ca commit 819f078

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

src/test/java/com/thealgorithms/tree/BinarySearchTree.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,36 @@ void testPrettyDisplay() {
8888
bst.prettyDisplay();
8989
assertTrue(true, "Pretty display executed successfully");
9090
}
91+
92+
/**
93+
* Tests insertion of negative values into the BST.
94+
* Verifies that the tree is not empty and remains balanced.
95+
*/
96+
@Test
97+
void testInsertNegativeValues() {
98+
BinarySearchTree bst = new BinarySearchTree();
99+
int[] negativeValues = {-10, -20, -5, -15};
100+
bst.populate(negativeValues);
101+
assertFalse(bst.isEmpty(), "BST should not be empty after inserting negative values");
102+
assertTrue(bst.balanced(), "BST with negative values should be balanced");
103+
}
104+
105+
/**
106+
* Tests insertion of duplicate values into the BST.
107+
* Verifies that the tree handles duplicates (either inserts or ignores them).
108+
* Note: Current BST implementation inserts duplicates to the right.
109+
*/
110+
@Test
111+
void testInsertDuplicateValues() {
112+
BinarySearchTree bst = new BinarySearchTree();
113+
int[] valuesWithDuplicates = {10, 20, 10, 30, 20};
114+
bst.populate(valuesWithDuplicates);
115+
assertFalse(bst.isEmpty(), "BST should not be empty after inserting duplicates");
116+
117+
// Optional: Check structure manually via traversal
118+
bst.inOrder(); // Output can be visually verified
119+
assertTrue(true, "BST handled duplicate values (check logic if duplicates are allowed)");
120+
}
91121

92122
/**
93123
* Tests balanced population using sorted array.

src/test/java/com/thealgorithms/tree/HeavyLightDecompositionTest.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.thealgorithms.tree;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.junit.jupiter.api.Assertions.assertFalse;
54
import static org.junit.jupiter.api.Assertions.assertTrue;
65

76
import org.junit.jupiter.api.BeforeEach;
@@ -51,37 +50,6 @@ void testUpdateNodeValue() {
5150
assertEquals(100, hld.queryMaxInPath(4, 5), "Updated value should be reflected in query");
5251
}
5352

54-
/**
55-
* Tests insertion of negative values into the BST.
56-
* Verifies that the tree is not empty and remains balanced.
57-
*/
58-
@Test
59-
void testInsertNegativeValues() {
60-
BinarySearchTree bst = new BinarySearchTree();
61-
int[] negativeValues = {-10, -20, -5, -15};
62-
bst.populate(negativeValues);
63-
assertFalse(bst.isEmpty(), "BST should not be empty after inserting negative values");
64-
assertTrue(bst.balanced(), "BST with negative values should be balanced");
65-
}
66-
67-
/**
68-
* Tests insertion of duplicate values into the BST.
69-
* Verifies that the tree handles duplicates (either inserts or ignores them).
70-
* Note: Current BST implementation inserts duplicates to the right.
71-
*/
72-
@Test
73-
void testInsertDuplicateValues() {
74-
BinarySearchTree bst = new BinarySearchTree();
75-
int[] valuesWithDuplicates = {10, 20, 10, 30, 20};
76-
bst.populate(valuesWithDuplicates);
77-
assertFalse(bst.isEmpty(), "BST should not be empty after inserting duplicates");
78-
79-
// Optional: Check structure manually via traversal
80-
bst.inOrder(); // Output can be visually verified
81-
assertTrue(true, "BST handled duplicate values (check logic if duplicates are allowed)");
82-
}
83-
84-
8553
/**
8654
* Tests the maximum value query in a skewed tree structure.
8755
*/

0 commit comments

Comments
 (0)