-
Notifications
You must be signed in to change notification settings - Fork 2
/
view-traversal-order.js
42 lines (36 loc) · 1.19 KB
/
view-traversal-order.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
/**
* Utility file for quickly viewing the order which
* a given traversal algorithm will visit people.
*/
var expect = require('chai').expect,
graph = require('./test/graphs/large.js'),
sdk = require('./test/lib/mock-sdk.js')(graph),
FSTraversal = require('./lib/fs-traversal.js');
var relationships = [],
order;
// Specify which algorithm we're testing
if(process.argv[1].indexOf(__filename) !== -1 && process.argv[2]){
order = process.argv[2];
} else {
console.error('Error: Must specify an order');
console.log('Usage: node view-traversal-order.js order');
process.exit();
}
// Setup/load relationships
var traversal = FSTraversal(sdk)
.order(order)
// Calc weights for all relationships
.person(function(person){
relationships.push({
name: person.name,
weight: traversal._calcWeight(traversal._fetched[person.id])
});
})
// Print results
.done(function(){
for(var i = 0; i < relationships.length; i++){
console.log('%s,%d', relationships[i].name, relationships[i].weight);
}
})
// Start
.traverse('1');