Skip to content

Commit f63e2b5

Browse files
committed
update tests for Sankey generators
1 parent 00e5d28 commit f63e2b5

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

test/jasmine/tests/sankey_d3_sankey_circular_test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ describe('d3-sankey-ciruclar', function() {
4747
expect(circularLinks.length).toEqual(2, 'there are two circular links');
4848
});
4949

50-
it('keep a list of nodes with positions in integer (col, height)', function() {
51-
checkArray('column', [0, 0, 2, 3, 1, 1]);
50+
it('keep a list of nodes with positions in integer (depth, height)', function() {
51+
checkArray('depth', [0, 0, 2, 3, 1, 1]);
5252
checkArray('height', [1, 3, 1, 0, 2, 0]);
5353
});
5454

@@ -60,6 +60,8 @@ describe('d3-sankey-ciruclar', function() {
6060
it('supports column reordering', function() {
6161
var reorder = [ 2, 2, 1, 1, 0, 0 ];
6262

63+
checkArray('column', [0, 0, 2, 3, 1, 1]);
64+
6365
var a = graph.nodes[0].x0;
6466
sankey.nodeAlign(function(node) {
6567
return reorder[node.pointNumber];

test/jasmine/tests/sankey_d3_sankey_test.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
var d3sankey = require('d3-sankey');
55

6-
var graph = {
6+
var data = {
77
'nodes': [{
88
'node': 0,
99
'name': 'node0'
@@ -53,6 +53,8 @@ var graph = {
5353

5454

5555
describe('d3-sankey', function() {
56+
var sankey;
57+
var graph;
5658
var margin = {
5759
top: 10,
5860
right: 10,
@@ -62,53 +64,67 @@ describe('d3-sankey', function() {
6264
var width = 1200 - margin.left - margin.right;
6365
var height = 740 - margin.top - margin.bottom;
6466

65-
var s;
66-
6767
beforeEach(function() {
68-
s = d3sankey
68+
sankey = d3sankey
6969
.sankey()
7070
.nodeWidth(36)
7171
.nodePadding(10)
72-
.nodes(graph.nodes)
73-
.links(graph.links)
72+
.nodes(data.nodes)
73+
.links(data.links)
7474
.size([width, height])
7575
.iterations(32);
76+
77+
graph = sankey();
7678
});
7779

80+
function checkArray(key, result) {
81+
var value = graph.nodes.map(function(obj) {
82+
return obj[key];
83+
});
84+
expect(value).toEqual(result, 'invalid property named ' + key);
85+
}
86+
87+
function checkRoundedArray(key, result) {
88+
var value = graph.nodes.map(function(obj) {
89+
return Math.round(obj[key]);
90+
});
91+
expect(value).toEqual(result, 'invalid property named ' + key);
92+
}
93+
7894
it('controls the width of nodes', function() {
79-
expect(s.nodeWidth()).toEqual(36, 'incorrect nodeWidth');
95+
expect(sankey.nodeWidth()).toEqual(36, 'incorrect nodeWidth');
8096
});
8197

8298
it('controls the padding between nodes', function() {
83-
expect(s.nodePadding()).toEqual(10, 'incorrect nodePadding');
99+
expect(sankey.nodePadding()).toEqual(10, 'incorrect nodePadding');
84100
});
85101

86102
it('controls the padding between nodes', function() {
87-
expect(s.nodePadding()).toEqual(10, 'incorrect nodePadding');
103+
expect(sankey.nodePadding()).toEqual(10, 'incorrect nodePadding');
88104
});
89105

90106
it('keep a list of nodes', function() {
91-
var nodeNames = s().nodes.map(function(obj) {
92-
return obj.name;
93-
});
94-
expect(nodeNames).toEqual(['node0', 'node1', 'node2', 'node3', 'node4']);
107+
checkArray('name', ['node0', 'node1', 'node2', 'node3', 'node4']);
95108
});
96109

97-
it('keep a list of nodes with x values', function() {
98-
var nodeNames = s().nodes.map(function(obj) {
99-
return Math.floor(obj.x0);
100-
});
101-
expect(nodeNames).toEqual([0, 0, 381, 762, 1144]);
110+
it('keep a list of nodes with x and y values', function() {
111+
checkRoundedArray('x0', [0, 0, 381, 763, 1144]);
112+
checkRoundedArray('y0', [0, 365, 184, 253, 0]);
113+
});
114+
115+
it('keep a list of nodes with positions in integer (depth, height)', function() {
116+
checkArray('depth', [0, 0, 1, 2, 3]);
117+
checkArray('height', [3, 3, 2, 1, 0]);
102118
});
103119

104120
it('keep a list of links', function() {
105-
var linkWidths = s().links.map(function(obj) {
121+
var linkWidths = sankey().links.map(function(obj) {
106122
return (obj.width);
107123
});
108124
expect(linkWidths).toEqual([177.5, 177.5, 177.5, 177.5, 177.5, 177.5, 355]);
109125
});
110126

111127
it('controls the size of the figure', function() {
112-
expect(s.size()).toEqual([1180, 720], 'incorrect size');
128+
expect(sankey.size()).toEqual([1180, 720], 'incorrect size');
113129
});
114130
});

0 commit comments

Comments
 (0)