-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcountUnivalTrees.test.js
68 lines (62 loc) · 1.5 KB
/
countUnivalTrees.test.js
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
import countUnivalTrees from "./countUnivalTrees";
import BinaryTreeNode from "./BinaryTreeNode";
describe(`countUnivalTrees()`, () => {
it(`returns count with leaves only`, () => {
/**
* Tree Structure:
* a
* / \
* a a
* /\
* a a
* \
* A
*/
const root = new BinaryTreeNode("a");
root.insertLeft("a");
root.insertRight("a");
root.right.insertLeft("a");
root.right.insertRight("a");
root.right.right.insertRight("A");
expect(countUnivalTrees(root)).toBe(3);
});
it(`returns count that adds leaves and unival subtrees`, () => {
/**
* Tree Structure:
* a
* / \
* c b
* /\
* b b
* \
* b
*/
const root = new BinaryTreeNode("a");
root.insertLeft("c");
root.insertRight("b");
root.right.insertLeft("b");
root.right.insertRight("b");
root.right.right.insertRight("b");
expect(countUnivalTrees(root)).toBe(5);
});
it(`returns count that adds leaves and unival subtrees (integers)`, () => {
/**
* Tree Structure:
* 0
* / \
* 1 0
* / \
* 1 0
* / \
* 1 1
*/
const root = new BinaryTreeNode(0);
root.insertLeft(1);
root.insertRight(0);
root.right.insertRight(0);
root.right.insertLeft(1);
root.right.left.insertLeft(1);
root.right.left.insertRight(1);
expect(countUnivalTrees(root)).toBe(5);
});
});