Skip to content

Commit 48f7ea1

Browse files
committed
Add one more test for BST.
1 parent 4132522 commit 48f7ea1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/data-structures/tree/binary-search-tree/__test__/BinarySearchTree.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,23 @@ describe('BinarySearchTree', () => {
7676

7777
expect(bst.toString()).toBe('obj1,obj2,obj3');
7878
});
79+
80+
it('should be traversed to sorted array', () => {
81+
const bst = new BinarySearchTree();
82+
83+
bst.insert(10);
84+
bst.insert(-10);
85+
bst.insert(20);
86+
bst.insert(-20);
87+
bst.insert(25);
88+
bst.insert(6);
89+
90+
expect(bst.toString()).toBe('-20,-10,6,10,20,25');
91+
expect(bst.root.height).toBe(2);
92+
93+
bst.insert(4);
94+
95+
expect(bst.toString()).toBe('-20,-10,4,6,10,20,25');
96+
expect(bst.root.height).toBe(3);
97+
});
7998
});

0 commit comments

Comments
 (0)