pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/TheAlgorithms/JavaScript/commit/e3d605c528272a561148dba03343801ba3024c99

Breadth FIrst Tree Traversal : Convert live test into Jest test. · TheAlgorithms/JavaScript@e3d605c · GitHub
Skip to content

Commit e3d605c

Browse files
committed
Breadth FIrst Tree Traversal : Convert live test into Jest test.
1 parent 036ac90 commit e3d605c

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

Trees/BreadthFirstTreeTraversal.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BinaryTree {
2222
for (let i = 1; i <= h; i++) {
2323
this.traverseLevel(this.root, i)
2424
}
25-
return this.traversal.toLocaleString()
25+
return this.traversal
2626
}
2727

2828
// Computing the height of the tree
@@ -48,19 +48,4 @@ class BinaryTree {
4848
}
4949
}
5050

51-
const binaryTree = new BinaryTree()
52-
const root = new Node(7)
53-
root.left = new Node(5)
54-
root.right = new Node(8)
55-
root.left.left = new Node(3)
56-
root.left.right = new Node(6)
57-
root.right.right = new Node(9)
58-
binaryTree.root = root
59-
60-
console.log(binaryTree.breadthFirst())
61-
62-
// 7
63-
// / \
64-
// 5 8
65-
// / \ \
66-
// 3 6 9
51+
export { BinaryTree, Node }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { BinaryTree, Node } from '../BreadthFirstTreeTraversal'
2+
3+
describe('Breadth First Tree Traversal', () => {
4+
const binaryTree = new BinaryTree()
5+
6+
const root = new Node(7)
7+
root.left = new Node(5)
8+
root.right = new Node(8)
9+
root.left.left = new Node(3)
10+
root.left.right = new Node(6)
11+
root.right.right = new Node(9)
12+
binaryTree.root = root
13+
14+
// Vizualization :
15+
//
16+
// 7
17+
// / \
18+
// 5 8
19+
// / \ \
20+
// 3 6 9
21+
22+
it('Binary tree - Level order traversal', () => {
23+
expect(binaryTree.traversal).toStrictEqual([])
24+
const traversal = binaryTree.breadthFirst()
25+
expect(traversal).toStrictEqual([7, 5, 8, 3, 6, 9])
26+
})
27+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy