@@ -29,7 +29,7 @@ describe('binarySearchTree tests', () => {
29
29
expect ( bst . max ( ) . getValue ( 90 ) ) ) ) ;
30
30
31
31
describe ( '.root()' , ( ) =>
32
- it ( 'should get the node with min value ' , ( ) =>
32
+ it ( 'should get the root node ' , ( ) =>
33
33
expect ( bst . root ( ) . getValue ( 50 ) ) ) ) ;
34
34
35
35
describe ( '.find(value)' , ( ) =>
@@ -79,7 +79,6 @@ describe('binarySearchTree tests', () => {
79
79
expect ( bst . count ( ) ) . to . equal ( 5 ) ;
80
80
} ) ;
81
81
82
-
83
82
it ( 'should remove a node with a left child only' , ( ) => {
84
83
bst . insert ( 30 ) ;
85
84
bst . remove ( 40 ) ;
@@ -96,6 +95,30 @@ describe('binarySearchTree tests', () => {
96
95
expect ( bst . find ( 90 ) . getLeft ( ) . getValue ( ) ) . to . equal ( 60 ) ;
97
96
expect ( bst . count ( ) ) . to . equal ( 4 ) ;
98
97
} ) ;
98
+
99
+ it ( 'should remove root node with right child' , ( ) => {
100
+ bst . insert ( 100 ) ;
101
+ bst . remove ( 60 ) ;
102
+ bst . remove ( 90 ) ;
103
+ bst . remove ( 30 ) ;
104
+ bst . remove ( 50 ) ;
105
+ expect ( bst . root ( ) . getValue ( ) ) . to . equal ( 100 ) ;
106
+ } ) ;
107
+
108
+ it ( 'should remove root node with left child' , ( ) => {
109
+ bst . insert ( 20 ) ;
110
+ bst . insert ( 30 ) ;
111
+ bst . insert ( 25 ) ;
112
+ bst . remove ( 30 ) ;
113
+ bst . remove ( 25 ) ;
114
+ bst . remove ( 100 ) ;
115
+ expect ( bst . root ( ) . getValue ( ) ) . to . equal ( 20 ) ;
116
+ } ) ;
117
+
118
+ it ( 'should remove root node' , ( ) => {
119
+ bst . remove ( 20 ) ;
120
+ expect ( bst . root ( ) ) . to . equal ( null ) ;
121
+ } ) ;
99
122
} ) ;
100
123
101
124
describe ( '.clear()' , ( ) => {
0 commit comments