mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +08:00
Remove duplicated methods from Graph class.
This commit is contained in:
parent
9bc2800848
commit
f7ebddc82d
@ -123,18 +123,6 @@ export default class Graph {
|
|||||||
return vertex.findEdge(endVertex);
|
return vertex.findEdge(endVertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} vertexKey
|
|
||||||
* @returns {GraphVertex}
|
|
||||||
*/
|
|
||||||
findVertexByKey(vertexKey) {
|
|
||||||
if (this.vertices[vertexKey]) {
|
|
||||||
return this.vertices[vertexKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
|
@ -32,14 +32,14 @@ describe('Graph', () => {
|
|||||||
expect(graph.getAllVertices()[0]).toEqual(vertexA);
|
expect(graph.getAllVertices()[0]).toEqual(vertexA);
|
||||||
expect(graph.getAllVertices()[1]).toEqual(vertexB);
|
expect(graph.getAllVertices()[1]).toEqual(vertexB);
|
||||||
|
|
||||||
const graphVertexA = graph.findVertexByKey(vertexA.getKey());
|
const graphVertexA = graph.getVertexByKey(vertexA.getKey());
|
||||||
const graphVertexB = graph.findVertexByKey(vertexB.getKey());
|
const graphVertexB = graph.getVertexByKey(vertexB.getKey());
|
||||||
|
|
||||||
expect(graph.toString()).toBe('A,B');
|
expect(graph.toString()).toBe('A,B');
|
||||||
expect(graphVertexA).toBeDefined();
|
expect(graphVertexA).toBeDefined();
|
||||||
expect(graphVertexB).toBeDefined();
|
expect(graphVertexB).toBeDefined();
|
||||||
|
|
||||||
expect(graph.findVertexByKey('not existing')).toBeNull();
|
expect(graph.getVertexByKey('not existing')).toBeUndefined();
|
||||||
|
|
||||||
expect(graphVertexA.getNeighbors().length).toBe(1);
|
expect(graphVertexA.getNeighbors().length).toBe(1);
|
||||||
expect(graphVertexA.getNeighbors()[0]).toEqual(vertexB);
|
expect(graphVertexA.getNeighbors()[0]).toEqual(vertexB);
|
||||||
@ -60,8 +60,8 @@ describe('Graph', () => {
|
|||||||
|
|
||||||
graph.addEdge(edgeAB);
|
graph.addEdge(edgeAB);
|
||||||
|
|
||||||
const graphVertexA = graph.findVertexByKey(vertexA.getKey());
|
const graphVertexA = graph.getVertexByKey(vertexA.getKey());
|
||||||
const graphVertexB = graph.findVertexByKey(vertexB.getKey());
|
const graphVertexB = graph.getVertexByKey(vertexB.getKey());
|
||||||
|
|
||||||
expect(graph.toString()).toBe('A,B');
|
expect(graph.toString()).toBe('A,B');
|
||||||
expect(graphVertexA).toBeDefined();
|
expect(graphVertexA).toBeDefined();
|
||||||
|
Loading…
Reference in New Issue
Block a user