Skip to content

Commit

Permalink
unit tests for #36 (margins in vertical and horizontal modes)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Jan 21, 2020
1 parent 8c66140 commit 79e2c82
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/horizontal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,20 @@ tape("horizontal offset", function(test) {
test.deepEqual(nodes.map(function(d) { return d.height === 200 / nodes.length; }), [true, true, true, true]);
test.end();
});

tape("horizontal layout works with margins", function(test) {

var nodes = [{w:1}, {w:2}, {w:3}];

var grid = gridding.gridding()
.valueHeight(d => d.w)
.mode("vertical")
.size([54, 30]).margin(3);
grid(nodes);

test.deepEqual(nodes.map(function(d) { return d.x; }), [3, 21, 39]);
test.deepEqual(nodes.map(function(d) { return d.y; }), [3, 3, 3]);
test.deepEqual(nodes.map(function(d) { return d.height; }), [8, 16, 24]);
test.deepEqual(nodes.map(function(d) { return d.width; }), [12, 12, 12]);
test.end();
});
18 changes: 18 additions & 0 deletions test/vertical-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,21 @@ tape("vertical layout should return width/n for Xs, and 0s for Ys", function(tes
test.deepEqual(nodes.map(function(d) { return d.y; }), [0, 0, 0, 0]);
test.end();
});


tape("vertical layout works with margins", function(test) {

var nodes = [{w:1}, {w:2}, {w:3}];

var grid = gridding.gridding()
.valueWidth(d => d.w)
.mode("vertical")
.size([18, 10]).margin(1);
grid(nodes);

test.deepEqual(nodes.map(function(d) { return d.x; }), [1, 5, 11]);
test.deepEqual(nodes.map(function(d) { return d.y; }), [1, 1, 1]);
test.deepEqual(nodes.map(function(d) { return d.height; }), [8, 8, 8]);
test.deepEqual(nodes.map(function(d) { return d.width; }), [2, 4, 6]);
test.end();
});

0 comments on commit 79e2c82

Please sign in to comment.