Skip to content

Commit 6f8b7de

Browse files
committed
Completed test cases for deletion
1 parent e78eae5 commit 6f8b7de

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
});

0 commit comments

Comments
 (0)