mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-05 16:36:41 +08:00
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:

committed by
Oleksii Trekhleb

parent
89fb0e6239
commit
88d038b5c8
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user