forked from blakeembrey/code-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary-search-tree-check.js
More file actions
113 lines (103 loc) · 1.56 KB
/
Copy pathbinary-search-tree-check.js
File metadata and controls
113 lines (103 loc) · 1.56 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var assert = require('assert');
var isBST = require('../../solutions/javascript/binary-search-tree-check');
var pass = {
value: 8,
left: {
value: 3,
left: {
value: 1
},
right: {
value: 6,
left: {
value: 4
},
right: {
value: 7
}
}
},
right: {
value: 10,
right: {
value: 14,
left: {
value: 13
}
}
}
};
var failLeft = {
value: 10,
left: {
value: 8,
left: {
value: 9
},
right: {
value: 10
}
},
right: {
value: 12
}
};
var failRight = {
value: 22,
left: {
value: 19
},
right: {
value: 29,
left: {
value: 26
},
right: {
value: 27
}
}
};
var failDuplicate = {
value: 13,
left: {
value: 10,
left: {
value: 7
},
right: {
value: 13
}
},
right: {
value: 15
}
};
var bstFalse = {
value: 3,
left: {
value: 2,
right: {
value: 10
}
},
right: {
value: 5
}
};
describe('binary search tree check', function () {
it('should pass a valid binary search tree', function () {
assert.ok(isBST(pass));
});
it('should fail with a left subtree that is greater', function () {
assert.ok(!isBST(failLeft));
});
it('should fail with a right subtree that is smaller', function () {
assert.ok(!isBST(failRight));
});
it('should fail with duplicate nodes', function () {
assert.ok(!isBST(failDuplicate));
});
it('should fail with bstFalse', function () {
assert.ok(!isBST(bstFalse));
});
});