Fix the findEdge method of the graph (#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
This commit is contained in:
m-maksyutin
2018-06-25 14:33:31 +03:00
committed by Oleksii Trekhleb
parent 89fb0e6239
commit 88d038b5c8
2 changed files with 9 additions and 2 deletions

View File

@ -115,6 +115,9 @@ export default class Graph {
*/
findEdge(startVertex, endVertex) {
const vertex = this.getVertexByKey(startVertex.getKey());
if (!vertex) {
return null;
}
return vertex.findEdge(endVertex);
}

View File

@ -87,9 +87,11 @@ describe('Graph', () => {
const graphEdgeAB = graph.findEdge(vertexA, vertexB);
const graphEdgeBA = graph.findEdge(vertexB, vertexA);
const graphEdgeAC = graph.findEdge(vertexB, vertexC);
const graphEdgeAC = graph.findEdge(vertexA, vertexC);
const graphEdgeCA = graph.findEdge(vertexC, vertexA);
expect(graphEdgeAC).toBeNull();
expect(graphEdgeCA).toBeNull();
expect(graphEdgeAB).toEqual(edgeAB);
expect(graphEdgeBA).toEqual(edgeAB);
expect(graphEdgeAB.weight).toBe(10);
@ -108,9 +110,11 @@ describe('Graph', () => {
const graphEdgeAB = graph.findEdge(vertexA, vertexB);
const graphEdgeBA = graph.findEdge(vertexB, vertexA);
const graphEdgeAC = graph.findEdge(vertexB, vertexC);
const graphEdgeAC = graph.findEdge(vertexA, vertexC);
const graphEdgeCA = graph.findEdge(vertexC, vertexA);
expect(graphEdgeAC).toBeNull();
expect(graphEdgeCA).toBeNull();
expect(graphEdgeBA).toBeNull();
expect(graphEdgeAB).toEqual(edgeAB);
expect(graphEdgeAB.weight).toBe(10);