forked from andreaferretti/paths-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.js
44 lines (38 loc) · 1019 Bytes
/
graph.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
import Graph from '../dist/node/graph.js'
import expect from 'expect.js'
import { range } from '../dist/node/ops.js'
let randomGraph = (n, density) => {
let nodes = range(0, n + 1)
let links = []
for (let i of range(0, n)) {
for (let j of range(i + 1, n)) {
if (Math.random() < density) {
links.push({
start: i,
end: j,
weight: 3 + 5 * Math.random()
})
}
}
}
return { nodes, links }
}
describe('the graph chart', () => {
let r = randomGraph(10, 0.25)
let graph = Graph({
data: r,
width: 450,
height: 400,
attraction: 7,
repulsion: 20
})
it('should return a chart with nodes and links in the right number', () => {
expect(graph.nodes).to.have.length(r.nodes.length)
expect(graph.curves).to.have.length(r.links.length)
})
it('should evolve under tick', () => {
let g1 = graph.tick()
expect(g1.nodes).to.have.length(r.nodes.length)
expect(g1.curves).to.have.length(r.links.length)
})
})