toolkit/javascript/d3/test/layout/tree-test.js
changeset 47 c0b4a8b5a012
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toolkit/javascript/d3/test/layout/tree-test.js	Thu Apr 10 14:20:23 2014 +0200
@@ -0,0 +1,41 @@
+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: []}).map(layout), [
+        {depth: 0, x: 0.5, y: 0}
+      ]);
+      assert.deepEqual(tree.nodes({children: [
+        {children: []},
+        {children: [{}]},
+        {children: [{}]}
+      ]}).map(layout), [
+        {depth: 0, x: .5,   y: 0},
+        {depth: 1, x: .125, y: 0.5},
+        {depth: 1, x: .375, y: 0.5},
+        {depth: 2, x: .375, y: 1},
+        {depth: 1, x: .875, y: 0.5},
+        {depth: 2, x: .875, y: 1}
+      ]);
+    }
+  }
+});
+
+function layout(node) {
+  return {
+    depth: node.depth,
+    x: node.x,
+    y: node.y
+  };
+}
+
+suite.export(module);