-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
49 lines (42 loc) · 979 Bytes
/
tests.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
var floyd = require('./floyd');
var numberPath = [1, 2, 3, 4, 0];
var simplePath = [
[1, 3],
[2],
[3],
[1],
];
// Sample with plenty of cycles.
var complexPath = [
{},
{'in': [3], 'out': [2, 3]},
{'in': [3]},
{'in': [0], 'out': [3]},
{'in': [1], 'out': [1]},
];
// Disconnected paths.
var disconnectedPath = [
{'out': [1]},
{},
{'out': [3]},
{'out': [2]},
];
var objectGraph = {
object1: ['object2'],
object2: ['object3'],
object3: ['object1'],
};
function runCycleTest(path, normalizePath) {
console.log("Looking for cycles in:");
console.log(path);
console.log("---");
var cycles = floyd.detectCycles(path, { normalizePath: !!normalizePath });
console.log("Found %d cycles:", cycles.length);
console.log(cycles);
console.log("\n");
}
runCycleTest(numberPath);
runCycleTest(simplePath);
runCycleTest(complexPath, true);
runCycleTest(disconnectedPath);
runCycleTest(objectGraph);