@@ -71,20 +71,29 @@ describe('Data Structure : Binary Search Tree', () => {
71
71
} ) ;
72
72
73
73
describe ( 'Check if BST `Is Empty`' , ( ) => {
74
- bst = new BinarySearchTree ( 6 ) ;
75
74
const keys = [ 4 , 9 , 2 , 5 , 8 , 12 ] ;
76
- keys . forEach ( el => bst . add ( el ) ) ;
75
+
76
+ beforeEach ( ( ) => {
77
+ bst = new BinarySearchTree ( 6 ) ;
78
+ keys . forEach ( el => bst . add ( el ) ) ;
79
+ } ) ;
80
+
81
+ afterEach ( ( ) => {
82
+ if ( bst . root ) bst . root = null ;
83
+ } ) ;
84
+
77
85
it ( 'Should return `false` when BST is not empty' , ( ) => {
78
86
expect ( bst . isEmpty ( ) ) . toEqual ( false ) ;
79
87
} ) ;
80
88
81
89
it ( 'Should return `true` when BST is empty' , ( ) => {
82
- keys . push ( 6 ) ;
83
- keys . forEach ( el => bst . remove ( el ) ) ;
90
+ bst . remove ( 6 ) ;
84
91
expect ( bst . isEmpty ( ) ) . toEqual ( true ) ;
85
92
} ) ;
86
93
} ) ;
87
94
95
+ /*
96
+
88
97
describe('Find maximum value in BST', () => {
89
98
bst = new BinarySearchTree(6);
90
99
[4, 9, 2, 5, 8, 12].forEach(el => bst.add(el));
@@ -167,4 +176,5 @@ describe('Data Structure : Binary Search Tree', () => {
167
176
expect(postOrderTraversal).toEqual([2, 5, 4, 8, 12, 9, 6]);
168
177
});
169
178
});
179
+ */
170
180
} ) ;
0 commit comments