Skip to content

Commit

Permalink
Add updateGraph function
Browse files Browse the repository at this point in the history
  • Loading branch information
cpettitt committed Sep 24, 2014
1 parent 1523d1d commit 6b29d6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/base-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ BaseGraph.prototype.setGraph = function(label) {
}
};

BaseGraph.prototype.updateGraph = function(fn) {
return this.setGraph(fn(this.getGraph()));
};

BaseGraph.prototype.nodeCount = function() {
return this._nodeCount;
};
Expand Down
14 changes: 14 additions & 0 deletions test/base-graph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ exports.tests = function(GraphConstructor) {
});
});

describe("updateGraph", function() {
it("updates the label for the graph", function() {
g.setGraph("foo");
g.updateGraph(function(old) { return old + "-bar"; });
expect(g.getGraph()).to.equal("foo-bar");
});

it("clears the label for the graph if no value is given", function() {
g.setGraph("foo");
g.updateGraph(function() {});
expect(g.getGraph()).to.be.undefined;
});
});

describe("hasNode", function() {
it("returns false if the node is not in the graph", function() {
expect(g.hasNode("node-not-in-graph")).to.be.false;
Expand Down

0 comments on commit 6b29d6d

Please sign in to comment.