forked from JackPu/JavaScript-Algorithm-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary-search-tree.test.js
More file actions
57 lines (40 loc) · 1.17 KB
/
Copy pathbinary-search-tree.test.js
File metadata and controls
57 lines (40 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
let BST = require('../code/binary-search-tree.js');
let arr = [1, 111, 2, 12, 180, 500, -12, 0];
describe('binary search tree', function () {
let bst = new BST();
it('insert', function () {
arr.forEach((item) => {
bst.insert(item);
})
expect(bst.root.data).toEqual(1);
});
it('find some value', function() {
expect(bst.find(111)).toEqual(111);
})
it('find min', function() {
expect(bst.findMin()).toEqual(-12);
})
it('find max', function() {
expect(bst.findMax()).toEqual(500);
})
it('in order',function() {
bst.inOrder(bst.root);
expect(bst.inOrderArr).toEqual([-12,0,1,2,12,111,180,500]);
})
it('pre order',function() {
bst.preOrder(bst.root);
expect(bst.preOrderArr).toEqual([1, -12, 0, 111, 2, 12, 180, 500]);
})
it('post order',function() {
bst.postOrder(bst.root);
expect(bst.postOrderArr).toEqual([0, -12, 12, 2, 500, 180, 111, 1]);
})
it('remove node' ,function() {
bst.remove(-12);
expect(bst.findMin()).toEqual(0);
})
it('remove the max value' ,function() {
bst.remove(500);
expect(bst.findMax()).toEqual(180);
})
})