Skip to content

Commit

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

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

BaseGraph.prototype.nodeCount = function() {
return this._nodeCount;
};
Expand Down Expand Up @@ -179,17 +175,6 @@ BaseGraph.prototype.setNodes = function(vs, label) {
return this;
};

BaseGraph.prototype.updateNode = function(v, updater) {
return this.setNode(v, updater(this.getNode(v), v));
};

BaseGraph.prototype.updateNodes = function(vs, updater) {
_.each(vs, function(v) {
this.updateNode(v, updater);
}, this);
return this;
};

BaseGraph.prototype.removeNode = function(v) {
if (_.has(this._nodes, v)) {
--this._nodeCount;
Expand Down Expand Up @@ -288,19 +273,6 @@ BaseGraph.prototype.setPath = function(vs, label) {
return this;
};

BaseGraph.prototype.updatePath = function(vs, updater) {
var self = this;
_.reduce(vs, function(v, w) {
self.setEdge(v, w, updater(self.getEdge(v, w), { v: v, w: w }));
return w;
});
return this;
};

BaseGraph.prototype.updateEdge = function(v, w, updater) {
return this.setEdge(v, w, updater(this.getEdge(v, w), { v: v, w: w }));
};

BaseGraph.prototype.removeEdge = function(v, w) {
var vOut = this._outEdges[v],
wIn = this._inEdges[w];
Expand Down
95 changes: 0 additions & 95 deletions test/base-graph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,6 @@ 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;
});

it("is chainable", function() {
var g2 = g.updateGraph(function(old) { return old + "-new"; });
expect(g).to.equal(g2);
});
});

describe("sources", function() {
it("includes a nodes whose only in-edge has been removed", function() {
g.setEdge("a", "b");
Expand Down Expand Up @@ -178,46 +159,6 @@ exports.tests = function(GraphConstructor) {
});
});

describe("updateNode", function() {
var updater = function(prev) { return prev + "-new"; };

it("creates the node if it isn't part of the graph", function() {
g.updateNode("key", updater);
expectSingleNodeGraph(g, "key", undefined + "-new");
});

it("replaces the node's label if the node is part of the graph", function() {
g.setNode("key", "label");
g.updateNode("key", updater);
expectSingleNodeGraph(g, "key", "label-new");
});

it("passes in the node's id", function() {
g.setNode("key", "label");
g.updateNode("key", function(prev, v) { return v + "-" + prev; });
expectSingleNodeGraph(g, "key", "key-label");
});

it("is chainable", function() {
var g2 = g.updateNode("key", updater);
expect(g).to.equal(g2);
});
});

describe("updateNodes", function() {
it("updates all of the specified nodes", function() {
g.setNode("a", "label");
g.updateNodes(["a", "b"], function(prev, v) { return v + "-" + prev; });
expect(g.getNode("a")).to.equal("a-label");
expect(g.getNode("b")).to.equal("b-undefined");
});

it("is chainable", function() {
var g2 = g.updateNodes(["key"], function() {});
expect(g).to.equal(g2);
});
});

describe("setDefaultNodeLabel", function() {
it("assigns the default value for created nodes", function() {
g.setDefaultNodeLabel(1);
Expand Down Expand Up @@ -461,42 +402,6 @@ exports.tests = function(GraphConstructor) {
});
});

describe("updateEdge", function() {
var updater = function(label) { return label + "-new"; };

it("adds and updates the edge if it does not exist", function() {
g.updateEdge("n1", "n2", updater);
expectSingleEdgeGraph(g, "n1", "n2", undefined + "-new");
});

it("updates the edge's label if it is in the graph", function() {
g.setEdge("n1", "n2", "label");
g.updateEdge("n1", "n2", updater);
expectSingleEdgeGraph(g, "n1", "n2", "label-new");
});

it("is chainable", function() {
var g2 = g.updateEdge("n1", "n2", updater);
expect(g).to.equal(g2);
});
});

describe("updatePath", function() {
it("updates all edges on the path", function() {
g.setEdge("a", "b", "label");
g.updatePath(["a", "b", "c"], function(prev, edge) {
return edge.v + "->" + edge.w + ":" + prev;
});
expect(g.getEdge("a", "b")).to.equal("a->b:label");
expect(g.getEdge("b", "c")).to.equal("b->c:undefined");
});

it("is chainable", function() {
var g2 = g.updatePath(["a", "b"], function() {});
expect(g).to.equal(g2);
});
});

describe("setDefaultEdgeLabel", function() {
it("assigns the default value for created edges", function() {
g.setDefaultEdgeLabel(1);
Expand Down

0 comments on commit ed38313

Please sign in to comment.