-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8867155
commit cbbd756
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
|
||
var insertEdge = function(graph, vertexNumber, to, EdgeNode) { | ||
var edgeNode = new EdgeNode(to, graph.edges[vertexNumber]); | ||
graph.edges[vertexNumber] = edgeNode; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use strict"; | ||
|
||
var graph = { | ||
edges: [] | ||
}; | ||
|
||
var resetGraph = function() { | ||
graph = { | ||
edges: [] | ||
}; | ||
}; | ||
|
||
var EdgeNode = function(to, next) { | ||
this.to = to; | ||
this.next = next; | ||
}; | ||
|
||
describe("insertEdge", function() { | ||
beforeEach(function() { | ||
resetGraph(); | ||
}); | ||
|
||
it("inserts an egdeNode into the graph", function() { | ||
insertEdge(graph, 1, 5, EdgeNode); | ||
expect(graph.edges[1].to).toEqual(5); | ||
expect(graph.edges[1].next).toEqual(undefined); | ||
/** | ||
[1]->5->|| | ||
*/ | ||
}); | ||
|
||
it("inserts an additional edgeNode to the head of the list of its vertex", function() { | ||
insertEdge(graph, 1, 5, EdgeNode); | ||
insertEdge(graph, 1, 3, EdgeNode); | ||
expect(graph.edges[1].to).toEqual(3); | ||
expect(graph.edges[1].next.to).toEqual(5); | ||
expect(graph.edges[1].next.next).toEqual(undefined); | ||
}); | ||
|
||
it("correctly inserts an edgeNode for another vertex", function() { | ||
insertEdge(graph, 1, 5, EdgeNode); | ||
insertEdge(graph, 1, 3, EdgeNode); | ||
insertEdge(graph, 2, 5, EdgeNode); | ||
expect(graph.edges[1].to).toEqual(3); | ||
expect(graph.edges[1].next.to).toEqual(5); | ||
expect(graph.edges[1].next.next).toEqual(undefined); | ||
expect(graph.edges[2].to).toEqual(5); | ||
expect(graph.edges[2].next).toEqual(undefined); | ||
}); | ||
}); |