From f7ebddc82d44d1249bd3482375e155210893e7d9 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Mon, 26 Nov 2018 06:30:56 +0200 Subject: [PATCH] Remove duplicated methods from Graph class. --- src/data-structures/graph/Graph.js | 12 ------------ src/data-structures/graph/__test__/Graph.test.js | 10 +++++----- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/data-structures/graph/Graph.js b/src/data-structures/graph/Graph.js index ae123ca1..ba0b6d01 100644 --- a/src/data-structures/graph/Graph.js +++ b/src/data-structures/graph/Graph.js @@ -123,18 +123,6 @@ export default class Graph { return vertex.findEdge(endVertex); } - /** - * @param {string} vertexKey - * @returns {GraphVertex} - */ - findVertexByKey(vertexKey) { - if (this.vertices[vertexKey]) { - return this.vertices[vertexKey]; - } - - return null; - } - /** * @return {number} */ diff --git a/src/data-structures/graph/__test__/Graph.test.js b/src/data-structures/graph/__test__/Graph.test.js index be6e9d7f..936a69b8 100644 --- a/src/data-structures/graph/__test__/Graph.test.js +++ b/src/data-structures/graph/__test__/Graph.test.js @@ -32,14 +32,14 @@ describe('Graph', () => { expect(graph.getAllVertices()[0]).toEqual(vertexA); expect(graph.getAllVertices()[1]).toEqual(vertexB); - const graphVertexA = graph.findVertexByKey(vertexA.getKey()); - const graphVertexB = graph.findVertexByKey(vertexB.getKey()); + const graphVertexA = graph.getVertexByKey(vertexA.getKey()); + const graphVertexB = graph.getVertexByKey(vertexB.getKey()); expect(graph.toString()).toBe('A,B'); expect(graphVertexA).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()[0]).toEqual(vertexB); @@ -60,8 +60,8 @@ describe('Graph', () => { graph.addEdge(edgeAB); - const graphVertexA = graph.findVertexByKey(vertexA.getKey()); - const graphVertexB = graph.findVertexByKey(vertexB.getKey()); + const graphVertexA = graph.getVertexByKey(vertexA.getKey()); + const graphVertexB = graph.getVertexByKey(vertexB.getKey()); expect(graph.toString()).toBe('A,B'); expect(graphVertexA).toBeDefined();