-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpathSum.test.js
More file actions
52 lines (41 loc) · 1.33 KB
/
Copy pathpathSum.test.js
File metadata and controls
52 lines (41 loc) · 1.33 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
const hasPathSum = require('./pathSum');
describe("hasPathSum", () => {
it('returns true when there is a path with the given sum', () => {
const root = {
val: 5,
left: {
val: 4,
left: {
val: 11,
left: { val: 7, left: null, right: null },
right: { val: 2, left: null, right: null }
},
right: null
},
right: {
val: 8,
left: { val: 13, left: null, right: null },
right: { val: 4, left: null, right: { val: 1, left: null, right: null } }
}
};
const sum = 22;
const result = hasPathSum(root, sum);
expect(result).toBe(true);
});
it('returns false when there is no path with the given sum', () => {
const root = {
val: 1,
left: { val: 2, left: null, right: null },
right: { val: 3, left: null, right: null }
};
const sum = 5;
const result = hasPathSum(root, sum);
expect(result).toBe(false);
});
it('returns false for an empty tree', () => {
const root = null;
const sum = 10;
const result = hasPathSum(root, sum);
expect(result).toBe(false);
});
});