-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
157 lines (134 loc) · 3.48 KB
/
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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Graphology Utils Unit Tests
* ============================
*/
var assert = require('assert'),
Graph = require('graphology');
var helpers = require('./helpers.js'),
layout = require('./index.js');
describe('graphology-layout-forceatlas2', function() {
describe('helpers', function() {
describe('#.graphToByteArrays', function() {
it('should work as expected.', function() {
var graph = new Graph();
graph.addNodesFrom({
John: {
size: 4,
x: 3,
y: 4
},
Martha: {
x: 10,
y: 5
},
Ada: {
x: 23,
y: -2
}
});
graph.addEdge('John', 'Martha');
graph.addEdge('Martha', 'Ada', {weight: 3});
var matrices = helpers.graphToByteArrays(graph);
assert.deepEqual(
Array.from(matrices.nodes),
[
3, 4, 0, 0, 0, 0, 2, 1, 4, 0,
10, 5, 0, 0, 0, 0, 3, 1, 1, 0,
23, -2, 0, 0, 0, 0, 2, 1, 1, 0
]
);
assert.deepEqual(
Array.from(matrices.edges),
[
0, 10, 0,
10, 20, 3
]
);
});
});
describe('#.collectLayoutChanges', function() {
it('should work as expected.', function() {
var graph = new Graph();
graph.addNodesFrom({
John: {
size: 4,
x: 3,
y: 4
},
Martha: {
x: 10,
y: 5
},
Ada: {
x: 23,
y: -2
}
});
var positions = helpers.collectLayoutChanges(graph, [
4, 5, 0, 0, 0, 0, 2, 1, 4, 0,
11, 6, 0, 0, 0, 0, 3, 1, 1, 0,
24, -1, 0, 0, 0, 0, 2, 1, 1, 0
]);
assert.deepEqual(positions, {
John: {x: 4, y: 5},
Martha: {x: 11, y: 6},
Ada: {x: 24, y: -1}
});
});
});
describe('#.applyLayoutChanges', function() {
it('should work as expecte.', function() {
var graph = new Graph();
graph.addNodesFrom({
John: {
x: 3,
y: 4
},
Martha: {
x: 10,
y: 5
},
Ada: {
x: 23,
y: -2
}
});
helpers.applyLayoutChanges(graph, [
4, 5, 0, 0, 0, 0, 2, 1, 4, 0,
11, 6, 0, 0, 0, 0, 3, 1, 1, 0,
24, -1, 0, 0, 0, 0, 2, 1, 1, 0
]);
var positions = {
John: graph.getNodeAttributes('John'),
Martha: graph.getNodeAttributes('Martha'),
Ada: graph.getNodeAttributes('Ada')
};
assert.deepEqual(positions, {
John: {x: 4, y: 5},
Martha: {x: 11, y: 6},
Ada: {x: 24, y: -1}
});
});
});
});
describe('synchronous', function() {
it('should throw if the graph is invalid.', function() {
assert.throws(function() {
layout(null);
}, /graphology/);
});
it('should throw if iterations are not valid.', function() {
assert.throws(function() {
layout(new Graph(), {});
}, /number/);
assert.throws(function() {
layout(new Graph(), -34);
}, /positive/);
});
it('should throw if settings are invalid.', function() {
assert.throws(function() {
layout(new Graph(), {iterations: 5, settings: {linLogMode: 45}});
}, /linLogMode/);
});
});
});