Skip to content

Commit 02d0a06

Browse files
SHEEVOOTSHEEVOOT
SHEEVOOT
authored and
SHEEVOOT
committed
Added Unit test for BST insert and delete
1 parent 42034d9 commit 02d0a06

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

src/.DS_Store

6 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const BST = require('.');
2+
3+
describe('Data Structure : Binary Search Tree', () => {
4+
it('Should be class', () => {
5+
expect(typeof BST.prototype.constructor).toEqual('function');
6+
});
7+
8+
describe('Binary Search Tree API', () => {
9+
let bst = null;
10+
11+
beforeEach(() => {
12+
bst = new BST(5);
13+
});
14+
15+
it('Should insert() element to Binary Search Tree', () => {
16+
bst.add(4);
17+
bst.add(9);
18+
bst.add(2);
19+
bst.insert(bst.root, 3);
20+
expect(bst.traverseInorder()).toEqual([2, 3, 4, 5, 9]);
21+
bst.insert(bst.root, 7);
22+
expect(bst.traverseInorder()).toEqual([2, 3, 4, 5, 7, 9]);
23+
});
24+
25+
it('Should delete() an element from Binary Search Tree', () => {
26+
bst.add(4);
27+
bst.add(9);
28+
bst.add(2);
29+
bst.delete(bst.root, 4);
30+
expect(bst.traverseInorder()).toEqual([2, 5, 9]);
31+
bst.delete(bst.root, 2);
32+
expect(bst.traverseInorder()).toEqual([5, 9]);
33+
});
34+
});
35+
});

0 commit comments

Comments
 (0)