-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreadth-first-search.test.js
69 lines (63 loc) · 1.32 KB
/
breadth-first-search.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const breadthFirstSearch = require('./breadth-first-search')
describe('breadth first search', () => {
describe('recursive solution', () => {
it('should return true if a search value is found', () => {
// arrange
const graph = {
id: 1,
value: 100,
edges: [
{
id: 2,
value: 102,
edges: [
{
id: 4,
value: 104,
edges: []
}
]
},
{
id: 3,
value: 103,
edges: []
}
]
}
// act
const actual = breadthFirstSearch(graph, 104)
// assert
expect(actual).toEqual(true)
})
it('should return false if a search value is not found', () => {
// arrange
const graph = {
id: 1,
value: 100,
edges: [
{
id: 2,
value: 102,
edges: [
{
id: 4,
value: 104,
edges: []
}
]
},
{
id: 3,
value: 103,
edges: []
}
]
}
// act
const actual = breadthFirstSearch(graph, 200)
// assert
expect(actual).toEqual(false)
})
})
})