Breadth FIrst Tree Traversal : Convert live test into Jest test.

This commit is contained in:
Eric Lavault
2021-10-11 14:48:06 +02:00
parent 036ac907ae
commit e3d605c528
2 changed files with 29 additions and 17 deletions

View File

@ -0,0 +1,27 @@
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.right.right = new Node(9)
binaryTree.root = root
// Vizualization :
//
// 7
// / \
// 5 8
// / \ \
// 3 6 9
it('Binary tree - Level order traversal', () => {
expect(binaryTree.traversal).toStrictEqual([])
const traversal = binaryTree.breadthFirst()
expect(traversal).toStrictEqual([7, 5, 8, 3, 6, 9])
})
})