Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88d038b

Browse files
m-maksyutintrekhleb
authored andcommitted
Fix the findEdge method of the graph (trekhleb#80)
* Fix LinkedList * Fix the prepend method for the LinkedList * Fix the remove method for the MinHeap * Correct a comment * Fix BST removal method * Fix the findEdge method of the graph
1 parent 89fb0e6 commit 88d038b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

‎src/data-structures/graph/Graph.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ export default class Graph {
115115
*/
116116
findEdge(startVertex, endVertex) {
117117
const vertex = this.getVertexByKey(startVertex.getKey());
118+
if (!vertex) {
119+
return null;
120+
}
118121
return vertex.findEdge(endVertex);
119122
}
120123

‎src/data-structures/graph/__test__/Graph.test.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ describe('Graph', () => {
8787

8888
const graphEdgeAB = graph.findEdge(vertexA, vertexB);
8989
const graphEdgeBA = graph.findEdge(vertexB, vertexA);
90-
const graphEdgeAC = graph.findEdge(vertexB, vertexC);
90+
const graphEdgeAC = graph.findEdge(vertexA, vertexC);
91+
const graphEdgeCA = graph.findEdge(vertexC, vertexA);
9192

9293
expect(graphEdgeAC).toBeNull();
94+
expect(graphEdgeCA).toBeNull();
9395
expect(graphEdgeAB).toEqual(edgeAB);
9496
expect(graphEdgeBA).toEqual(edgeAB);
9597
expect(graphEdgeAB.weight).toBe(10);
@@ -108,9 +110,11 @@ describe('Graph', () => {
108110

109111
const graphEdgeAB = graph.findEdge(vertexA, vertexB);
110112
const graphEdgeBA = graph.findEdge(vertexB, vertexA);
111-
const graphEdgeAC = graph.findEdge(vertexB, vertexC);
113+
const graphEdgeAC = graph.findEdge(vertexA, vertexC);
114+
const graphEdgeCA = graph.findEdge(vertexC, vertexA);
112115

113116
expect(graphEdgeAC).toBeNull();
117+
expect(graphEdgeCA).toBeNull();
114118
expect(graphEdgeBA).toBeNull();
115119
expect(graphEdgeAB).toEqual(edgeAB);
116120
expect(graphEdgeAB.weight).toBe(10);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /