Skip to content

Commit

Permalink
tests for #157
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Aug 12, 2020
1 parent 39f420c commit a743d15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/treemap/binary-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ tape("treemapBinary(parent, x0, y0, x1, y1) generates a binary treemap layout",
]);
test.end();
});

tape("treemapBinary does not break on 0-sized inputs", function(test) {
const data = ({children: [{value: 0}, {value: 0}, {value: 1}]});
const root = d3_hierarchy.hierarchy(data).sum(d => d.value);
const treemap = d3_hierarchy.treemap().tile(d3_hierarchy.treemapBinary);
treemap(root);
const a = root.leaves().map(d => [d.x0, d.x1, d.y0, d.y1]);
test.deepEqual(a, [[0, 1, 0, 0], [1, 1, 0, 0], [0, 1, 0, 1]]);
test.end();
});
10 changes: 10 additions & 0 deletions test/treemap/resquarify-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ tape("treemapResquarify.ratio(ratio) is unstable if the ratio is changed", funct
]);
test.end();
});

tape("treemapResquarify does not break on 0-sized inputs", function(test) {
var root = d3_hierarchy.hierarchy({children: [{children:[{value: 0}]}, {value: 1}]});
const treemap = d3_hierarchy.treemap().tile(d3_hierarchy.treemapResquarify);
treemap(root.sum(d => d.value));
treemap(root.sum(d => d.sum));
const a = root.leaves().map(d => [d.x0, d.x1, d.y0, d.y1]);
test.deepEqual(a, [[0, 1, 0, 0], [0, 1, 0, 0]]);
test.end();
});

0 comments on commit a743d15

Please sign in to comment.