|
1 | | -const {GraphFactory, BFS} = require('../index'); |
| 1 | +const {GraphFactory, bfs} = require('../index'); |
2 | 2 |
|
3 | | -describe("BreadthFirstSearch", () => { |
| 3 | +describe('BreadthFirstSearch', () => { |
4 | 4 | let graph = null; |
5 | 5 |
|
6 | 6 | beforeEach(() => { |
7 | 7 | graph = GraphFactory.getGraph(); |
8 | 8 | }); |
9 | 9 |
|
10 | | - it("should throw error on bad graph", () => { |
| 10 | + it('should throw error on bad graph', () => { |
11 | 11 | expect(() => { |
12 | | - BFS({}); |
13 | | - }).toThrow("Graph should implement a getNeighbors function"); |
| 12 | + bfs({}); |
| 13 | + }).toThrow('Graph should implement a getNeighbors function'); |
14 | 14 | }); |
15 | 15 |
|
16 | | - it("should throw error on no source vertex", () => { |
| 16 | + it('should throw error on no source vertex', () => { |
17 | 17 | expect(() => { |
18 | | - BFS(graph); |
19 | | - }).toThrow("source should be a number"); |
| 18 | + bfs(graph); |
| 19 | + }).toThrow('source should be a number'); |
20 | 20 | }); |
21 | 21 |
|
22 | | - it("simple bi-directional graph where target is reachable", () => { |
| 22 | + it('simple bi-directional graph where target is reachable', () => { |
23 | 23 | graph.addEdge(0, 1); |
24 | 24 | graph.addEdge(0, 3); |
25 | 25 | graph.addEdge(1, 2); |
26 | | - expect(BFS(graph, 0, 3)).toEqual({ |
| 26 | + expect(bfs(graph, 0, 3)).toEqual({ |
27 | 27 | order: [0, 1, 3, 2], |
28 | | - found: true |
| 28 | + found: true, |
29 | 29 | }); |
30 | 30 | }); |
31 | 31 |
|
32 | | - it("complex bi-directional graph where target is reachable", () => { |
| 32 | + it('complex bi-directional graph where target is reachable', () => { |
33 | 33 | graph.addEdge(0, 1); |
34 | 34 | graph.addEdge(0, 2); |
35 | 35 | graph.addEdge(1, 3); |
36 | 36 | graph.addEdge(3, 4); |
37 | 37 | graph.addEdge(4, 2); |
38 | | - expect(BFS(graph, 0, 3)).toEqual({ |
| 38 | + expect(bfs(graph, 0, 3)).toEqual({ |
39 | 39 | order: [0, 1, 2, 3, 4], |
40 | | - found: true |
| 40 | + found: true, |
41 | 41 | }); |
42 | 42 | }); |
43 | | - |
44 | | - it("complex uni-directional graph where target is reachable", () => { |
| 43 | + |
| 44 | + it('complex uni-directional graph where target is reachable', () => { |
45 | 45 | graph.addEdge(0, 1, false); |
46 | 46 | graph.addEdge(0, 2, false); |
47 | 47 | graph.addEdge(1, 3, false); |
48 | 48 | graph.addEdge(3, 4, false); |
49 | 49 | graph.addEdge(3, 5, false); |
50 | 50 | graph.addEdge(4, 2, false); |
51 | | - expect(BFS(graph, 0, 3)).toEqual({ |
| 51 | + expect(bfs(graph, 0, 3)).toEqual({ |
52 | 52 | order: [0, 1, 2, 3, 4, 5], |
53 | | - found: true |
| 53 | + found: true, |
54 | 54 | }); |
55 | 55 | }); |
56 | 56 |
|
57 | | - it("simple bi-directional graph where target is not present", () => { |
| 57 | + it('simple bi-directional graph where target is not present', () => { |
58 | 58 | graph.addEdge(0, 1); |
59 | 59 | graph.addEdge(0, 3); |
60 | 60 | graph.addEdge(1, 2); |
61 | | - expect(BFS(graph, 0, 5)).toEqual({ |
| 61 | + expect(bfs(graph, 0, 5)).toEqual({ |
62 | 62 | order: [0, 1, 3, 2], |
63 | | - found: false |
| 63 | + found: false, |
64 | 64 | }); |
65 | 65 | }); |
66 | 66 | }); |
0 commit comments