-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryTreeRightSideView.test.js
More file actions
45 lines (39 loc) · 1.46 KB
/
Copy pathbinaryTreeRightSideView.test.js
File metadata and controls
45 lines (39 loc) · 1.46 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
const binaryTreeRightSideView = require('./binaryTreeRightSideView');
const TreeNode = require('../TreeNode');
describe('binaryTreeRightSideView', () => {
it('should return an empty array for an empty tree', () => {
const root = null;
const expected = [];
const result = binaryTreeRightSideView(root);
expect(result).toEqual(expected);
});
it('should return the correct right side view for a tree with a single node', () => {
const root = new TreeNode(1);
const expected = [1];
const result = binaryTreeRightSideView(root);
expect(result).toEqual(expected);
});
it('should return the correct right side view for a balanced tree', () => {
// Create a balanced tree
const root = new TreeNode(1);
root.left = new TreeNode(2);
root.right = new TreeNode(3);
root.left.left = new TreeNode(4);
root.left.right = new TreeNode(5);
root.right.left = new TreeNode(6);
root.right.right = new TreeNode(7);
const expected = [1, 3, 7];
const result = binaryTreeRightSideView(root);
expect(result).toEqual(expected);
});
it('should return the correct right side view for an unbalanced tree', () => {
// Create an unbalanced tree
const root = new TreeNode(1);
root.left = new TreeNode(2);
root.left.left = new TreeNode(4);
root.left.left.right = new TreeNode(5);
const expected = [1, 2, 4, 5];
const result = binaryTreeRightSideView(root);
expect(result).toEqual(expected);
});
});