forked from cytoscape/cytoscape.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection-metadata.js
94 lines (74 loc) · 2.4 KB
/
collection-metadata.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var expect = require('chai').expect;
var cytoscape = require('../build/cytoscape.js', cytoscape);
describe('Collection metadata', function(){
var cy;
// test setup
beforeEach(function(done){
cytoscape({
elements: {
nodes: [
{ data: { id: 'n1' } },
{ data: { id: 'n2' } },
{ data: { id: 'n3' } },
{ data: { id: 'n4' } },
{ data: { id: 'n5' } }
],
edges: [
{ data: { id: 'n1n2', source: 'n1', target: 'n2' } },
{ data: { id: 'n2n3', source: 'n2', target: 'n3' } },
{ data: { id: 'n3n4', source: 'n3', target: 'n4' } },
{ data: { id: 'n4n5', source: 'n4', target: 'n5' } },
{ data: { id: 'n5n1', source: 'n5', target: 'n1' } },
{ data: { id: 'n1n3', source: 'n1', target: 'n3' } },
{ data: { id: 'n3n5', source: 'n3', target: 'n5' } },
{ data: { id: 'n5n2', source: 'n5', target: 'n2' } },
{ data: { id: 'n2n4', source: 'n2', target: 'n4' } },
{ data: { id: 'n4n1', source: 'n4', target: 'n1' } }
]
},
ready: function(){
cy = this;
done();
}
});
});
it('node.degree()', function(){
var nodes = cy.nodes();
for( var i = 0; i < nodes.length; i++ ){
expect( nodes[i].degree() ).to.equal( 4 );
}
});
it('node.indegree()', function(){
var nodes = cy.nodes();
for( var i = 0; i < nodes.length; i++ ){
expect( nodes[i].indegree() ).to.equal( 2 );
}
});
it('node.outdegree()', function(){
var nodes = cy.nodes();
for( var i = 0; i < nodes.length; i++ ){
expect( nodes[i].outdegree() ).to.equal( 2 );
}
});
it('nodes.totalDegree()', function(){
expect( cy.nodes().totalDegree() ).to.equal( 4 * 5 );
});
it('nodes.minDegree()', function(){
expect( cy.nodes().minDegree() ).to.equal( 4 );
});
it('nodes.maxDegree()', function(){
expect( cy.nodes().maxDegree() ).to.equal( 4 );
});
it('nodes.minIndegree()', function(){
expect( cy.nodes().minIndegree() ).to.equal( 2 );
});
it('nodes.maxIndegree()', function(){
expect( cy.nodes().maxIndegree() ).to.equal( 2 );
});
it('nodes.minOutdegree()', function(){
expect( cy.nodes().minOutdegree() ).to.equal( 2 );
});
it('nodes.maxOutdegree()', function(){
expect( cy.nodes().maxOutdegree() ).to.equal( 2 );
});
});