-
Notifications
You must be signed in to change notification settings - Fork 611
/
Copy pathrank-test.js
41 lines (37 loc) · 1.09 KB
/
rank-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
let expect = require("../chai").expect;
let rank = require("../../lib/rank");
let Graph = require("@dagrejs/graphlib").Graph;
describe("rank", () => {
let RANKERS = [
"longest-path", "tight-tree",
"network-simplex", "unknown-should-still-work"
];
let g;
beforeEach(() => {
g = new Graph()
.setGraph({})
.setDefaultNodeLabel(() => ({}))
.setDefaultEdgeLabel(() => ({ minlen: 1, weight: 1 }))
.setPath(["a", "b", "c", "d", "h"])
.setPath(["a", "e", "g", "h"])
.setPath(["a", "f", "g"]);
});
RANKERS.forEach(ranker => {
describe(ranker, () => {
it("respects the minlen attribute", () => {
g.graph().ranker = ranker;
rank(g);
g.edges().forEach(e => {
let vRank = g.node(e.v).rank;
let wRank = g.node(e.w).rank;
expect(wRank - vRank).to.be.gte(g.edge(e).minlen);
});
});
it("can rank a single node graph", () => {
let g = new Graph().setGraph({}).setNode("a", {});
rank(g, ranker);
expect(g.node("a").rank).to.equal(0);
});
});
});
});