forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreadthFirstTreeTraversal.test.js
38 lines (32 loc) · 1.01 KB
/
BreadthFirstTreeTraversal.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
import { BinaryTree, Node } from '../BreadthFirstTreeTraversal'
describe('Breadth First Tree Traversal', () => {
const binaryTree = new BinaryTree()
const root = new Node(7)
root.left = new Node(5)
root.right = new Node(8)
root.left.left = new Node(3)
root.left.right = new Node(6)
root.left.right.right = new Node(9)
binaryTree.root = root
// Visualization :
//
// 7
// / \
// 5 8
// / \
// 3 6
// \
// 9
it('Binary tree - Empty case', () => {
const emptyTree = new BinaryTree()
expect(emptyTree.breadthFirstIterative()).toStrictEqual([])
})
it('Binary tree - Level order recursive traversal', () => {
const traversal = binaryTree.breadthFirstRecursive()
expect(traversal).toStrictEqual([7, 5, 8, 3, 6, 9])
})
it('Binary tree - Level order iterative traversal', () => {
const traversal = binaryTree.breadthFirstIterative()
expect(traversal).toStrictEqual([7, 5, 8, 3, 6, 9])
})
})