Algorithms and Data Structures implemented in JavaScript for beginners, following best practices.
import { breadthFirstShortestPath } from '../BreadthFirstShortestPath'
describe('BreadthFirstShortestPath', () => {
const graph = {
A: ['B', 'D'],
B: ['E'],
C: ['D'],
D: ['A'],
E: ['D'],
F: ['G'],
G: []
}
/*
A <-> B
ʌ |
| |
v v
C --> D <-- E
F --> G
*/
it('should return the visited nodes', () => {
expect(breadthFirstShortestPath(graph, 'C', 'E')).toEqual([
'C',
'D',
'A',
'B',
'E'
])
expect(breadthFirstShortestPath(graph, 'E', 'B')).toEqual([
'E',
'B'
expect(breadthFirstShortestPath(graph, 'F', 'G')).toEqual(['F', 'G'])
expect(breadthFirstShortestPath(graph, 'A', 'G')).toEqual([])
})