Skip to content

Commit

Permalink
More fixing for getChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
cpettitt committed Sep 24, 2014
1 parent dd06114 commit d387aa8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,17 @@ Graph.prototype.getParent = function(v) {
};

Graph.prototype.getChildren = function(v) {
if (this._isCompound) {
if (_.isUndefined(v)) {
v = GRAPH_NODE;
}
if (_.isUndefined(v)) {
v = GRAPH_NODE;
}

if (this._isCompound) {
var children = this._children[v];
if (children) {
return _.keys(children);
}
} else if (v === GRAPH_NODE) {
return this.nodes();
} else if (this.hasNode(v)) {
return [];
}
Expand Down
7 changes: 7 additions & 0 deletions test/graph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ describe("Graph", function() {
expect(g.getChildren("a")).eqls([]);
});

it ("returns all nodes for the root of a non-compound graph", function() {
var g = new Graph();
g.setNode("a");
g.setNode("b");
expect(_.sortBy(g.getChildren())).eqls(["a", "b"]);
});

it("returns children for the node", function() {
g.setParent("a", "parent");
g.setParent("b", "parent");
Expand Down

0 comments on commit d387aa8

Please sign in to comment.