Skip to content

Commit

Permalink
Add test for tree layout.
Browse files Browse the repository at this point in the history
For now, test the bug we just fixed.
  • Loading branch information
mbostock committed Aug 19, 2011
1 parent 43aeb60 commit 3c0f299
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions d3.layout.js
Expand Up @@ -1484,8 +1484,8 @@ d3.layout.tree = function() {
function firstWalk(node, previousSibling) {
var children = node.children,
layout = node._tree;
if (children && children.length) {
var n = children.length,
if (children && (n = children.length)) {
var n,
firstChild = children[0],
previousChild,
ancestor = firstChild,
Expand Down
2 changes: 1 addition & 1 deletion d3.layout.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/layout/tree.js
Expand Up @@ -11,8 +11,8 @@ d3.layout.tree = function() {
function firstWalk(node, previousSibling) {
var children = node.children,
layout = node._tree;
if (children && children.length) {
var n = children.length,
if (children && (n = children.length)) {
var n,
firstChild = children[0],
previousChild,
ancestor = firstChild,
Expand Down
21 changes: 21 additions & 0 deletions test/layout/tree-test.js
@@ -0,0 +1,21 @@
require("../env");
require("../../d3");
require("../../d3.layout");

var vows = require("vows"),
assert = require("assert");

var suite = vows.describe("d3.layout.tree");

suite.addBatch({
"tree": {
topic: d3.layout.tree,
"can handle an empty children array": function(tree) {
assert.deepEqual(tree.nodes({children: []}), [
{children: [], depth: 0, x: 0.5, y: 0}
]);
}
}
});

suite.export(module);

0 comments on commit 3c0f299

Please sign in to comment.