Skip to content

Commit 346fc06

Browse files
committed
Add cycle test case
1 parent 4da2e8e commit 346fc06

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/graphs/searching/bfs.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,3 @@
5050
exports.bfs = bfs;
5151

5252
}((typeof window === 'undefined') ? module.exports : window));
53-
54-
console.log(exports.bfs(
55-
[[0, 0, 0, 0, 1],
56-
[0, 0, 0, 1, 0],
57-
[0, 0, 0, 0, 0],
58-
[1, 0, 1, 0, 0],
59-
[0, 1, 0, 1, 0]], 0, 2));

test/graphs/searching/bfs.spec.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
/* jshint multistr: true */
2+
13
'use strict';
24

3-
var sampleGraph = [[1, 1, 1, 0, 0, 0],
4-
[0, 1, 1, 1, 0, 0],
5-
[1, 0, 1, 1, 1, 0],
6-
[0, 1, 0, 1, 1, 0],
7-
[0, 1, 0, 1, 1, 0],
8-
[0, 1, 0, 1, 1, 0],
9-
[0, 0, 1, 1, 1, 1],
10-
[0, 0, 0, 0, 1, 1]];
5+
var graph = [[0, 0, 0, 0, 1],
6+
[0, 0, 0, 1, 0],
7+
[0, 0, 0, 0, 0],
8+
[1, 0, 1, 0, 0],
9+
[0, 1, 0, 1, 0]];
1110

1211
var bfs = require('../../../src/graphs/searching/bfs').bfs;
1312

@@ -19,7 +18,11 @@ describe('BFS', function () {
1918

2019
it('should return the correct output when used with\
2120
source node equals target node', function () {
21+
expect(bfs(graph, 2, 2)).toEqual([2]);
22+
});
2223

24+
it('should return work with cycles', function () {
25+
expect(bfs(graph, 0, 2)).toEqual([0, 4, 3, 2]);
2326
});
2427

2528
});

0 commit comments

Comments
 (0)