Skip to content

Commit ed4697f

Browse files
committed
Add tests
1 parent 79bedef commit ed4697f

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
package-lock.json
3+
*.swp

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ module.exports = function Graph(serialized){
8888
// Sets the weight of the given edge.
8989
function setEdgeWeight(u, v, weight){
9090
edgeWeights[encodeEdge(u, v)] = weight;
91+
return graph;
9192
}
9293

9394
// Gets the weight of the given edge.

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,24 @@ describe("Graph", function() {
313313
});
314314

315315
describe("Edge Weights", function() {
316+
316317
it("Should set and get an edge weight.", function (){
317318
var graph = Graph().addEdge("a", "b", 5);
318319
assert.equal(graph.getEdgeWeight("a", "b"), 5);
319320
});
321+
322+
it("Should set edge weight via setEdgeWeight.", function (){
323+
var graph = Graph()
324+
.addEdge("a", "b")
325+
.setEdgeWeight("a", "b", 5);
326+
assert.equal(graph.getEdgeWeight("a", "b"), 5);
327+
});
328+
329+
it("Should return weight of 1 if no weight set.", function (){
330+
var graph = Graph().addEdge("a", "b");
331+
assert.equal(graph.getEdgeWeight("a", "b"), 1);
332+
});
333+
320334
});
321335
});
322336

0 commit comments

Comments
 (0)