Skip to content

Commit 58dcda8

Browse files
committed
Added tests for verifying tree was created as expected.
1 parent f5494e9 commit 58dcda8

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/_DataStructures_/Trees/BinarySearchTree/bst-insertion.test.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ const BinarySearchTree = require('./index');
22

33
describe('Binary Search Tree', () => {
44
let bst;
5-
let rootsLeftChild, rootsRightChild;
6-
let rootsLeftChildsLeftChild, rootsLeftChildsRightChild;
7-
let rootsRightChildsLeftChild, rootsRightChildsRightChild;
5+
let rootsLeftChild;
6+
let rootsRightChild;
7+
let rootsLeftChildsLeftChild;
8+
let rootsLeftChildsRightChild;
9+
let rootsRightChildsLeftChild;
10+
let rootsRightChildsRightChild;
811

912
describe('Creates a binary search tree', () => {
1013
it('should create a bst with root 100', () => {
@@ -48,4 +51,18 @@ describe('Binary Search Tree', () => {
4851
expect(rootsRightChildsRightChild.value).toEqual(600);
4952
});
5053
});
54+
55+
describe('Check insertion was as expected', () => {
56+
it('Inorder traversal of the created bst should be [ 10, 20, 30, 100, 400, 500, 600 ]', () => {
57+
expect(bst.traverseInorder()).toEqual([10, 20, 30, 100, 400, 500, 600]);
58+
});
59+
60+
it('Preorder traversal of the created bst should be [ 100, 20, 10, 30, 500, 400, 600 ]', () => {
61+
expect(bst.traversePreorder()).toEqual([100, 20, 10, 30, 500, 400, 600]);
62+
});
63+
64+
it('Postorder traversal of the created bst should be [ 10, 30, 20, 400, 600, 500, 100 ]', () => {
65+
expect(bst.traversePostorder()).toEqual([10, 30, 20, 400, 600, 500, 100]);
66+
});
67+
});
5168
});

0 commit comments

Comments
 (0)