File tree 1 file changed +37
-0
lines changed
src/_DataStructures_/Trees/BinarySearchTree
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ const BinarySearchTree = require ( './index' ) ;
2
+ const heightOfBST = require ( './height-of-bst/index' ) ;
3
+
4
+ describe ( 'Binary search tree traversals' , ( ) => {
5
+ let bst ;
6
+
7
+ describe ( 'Creates BST' , ( ) => {
8
+ it ( 'should create BST' , ( ) => {
9
+ // Creates BST
10
+ bst = new BinarySearchTree ( 6 ) ;
11
+ bst . add ( 4 ) ;
12
+ bst . add ( 9 ) ;
13
+ bst . add ( 2 ) ;
14
+ bst . add ( 5 ) ;
15
+ bst . add ( 8 ) ;
16
+ bst . add ( 12 ) ;
17
+ } ) ;
18
+ } ) ;
19
+
20
+ describe ( 'BST node deletions' , ( ) => {
21
+ it ( 'should check height of bst to be 3 prior deletion' , ( ) => {
22
+ expect ( heightOfBST ( bst . root ) ) . toEqual ( 3 ) ;
23
+ } ) ;
24
+
25
+ it ( 'deleting leaf element does not affect tree height if it has sibling' , ( ) => {
26
+ bst . remove ( 2 ) ;
27
+ bst . remove ( 8 ) ;
28
+ expect ( heightOfBST ( bst . root ) ) . toEqual ( 3 ) ;
29
+ } ) ;
30
+
31
+ it ( 'deleting leaf element does affect tree height if it has no-sibling' , ( ) => {
32
+ bst . remove ( 5 ) ;
33
+ bst . remove ( 12 ) ;
34
+ expect ( heightOfBST ( bst . root ) ) . toEqual ( 2 ) ;
35
+ } ) ;
36
+ } ) ;
37
+ } ) ;
You can’t perform that action at this time.
0 commit comments