mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-05 16:36:41 +08:00
Add Bellman-Ford.
This commit is contained in:
@ -32,6 +32,13 @@ export default class Graph {
|
||||
return vertex.getNeighbors();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {GraphVertex[]}
|
||||
*/
|
||||
getAllVertices() {
|
||||
return Object.values(this.vertices);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {GraphEdge} edge
|
||||
* @returns {Graph}
|
||||
|
@ -28,6 +28,10 @@ describe('Graph', () => {
|
||||
|
||||
graph.addEdge(edgeAB);
|
||||
|
||||
expect(graph.getAllVertices().length).toBe(2);
|
||||
expect(graph.getAllVertices()[0]).toEqual(vertexA);
|
||||
expect(graph.getAllVertices()[1]).toEqual(vertexB);
|
||||
|
||||
const graphVertexA = graph.findVertexByKey(vertexA.getKey());
|
||||
const graphVertexB = graph.findVertexByKey(vertexB.getKey());
|
||||
|
||||
|
Reference in New Issue
Block a user