diff --git a/package.json b/package.json index b29031ae..0ff89a36 100644 --- a/package.json +++ b/package.json @@ -30,4 +30,3 @@ "npm": ">=6.9.0" } } - diff --git a/src/data-structures/graph/Graph.js b/src/data-structures/graph/Graph.js index ad418241..22a47437 100644 --- a/src/data-structures/graph/Graph.js +++ b/src/data-structures/graph/Graph.js @@ -330,9 +330,7 @@ export default class Graph { if (visited[index]) return false; - - console.log(index); - + visited[index] = true; recStack[index] = true; diff --git a/src/data-structures/graph/__test__/GraphVertex.test.js b/src/data-structures/graph/__test__/GraphVertex.test.js index eafde201..1a4d2e2f 100644 --- a/src/data-structures/graph/__test__/GraphVertex.test.js +++ b/src/data-structures/graph/__test__/GraphVertex.test.js @@ -166,10 +166,14 @@ describe('GraphVertex', () => { it('should represent a vertex', () => { const vertex = new GraphVertex('A'); - console.log(vertex.toString()) expect(vertex.toString()).toEqual('A'); }); + it('should represent a vertex with decorator', () => { + const vertex = new GraphVertex('A'); + expect(vertex.toString((value) => `Name: ${value}`)).toEqual('Name: A'); + }); + it('should calculate vertex degree', () => { const vertexA = new GraphVertex('A'); const vertexB = new GraphVertex('B'); diff --git a/src/server.js b/src/server.js index 90cd0548..63ffea32 100644 --- a/src/server.js +++ b/src/server.js @@ -35,6 +35,7 @@ app.get('/', (req, res) => { let C = new GraphVertex('C'); let D = new GraphVertex('D'); let E = new GraphVertex('E'); + let F = new GraphVertex('F'); // Vertices let AB = new GraphEdge(A, B); @@ -42,12 +43,17 @@ app.get('/', (req, res) => { let CD = new GraphEdge(C, D); let CE = new GraphEdge(C, E); let EB = new GraphEdge(E, B); + let CF = new GraphEdge(C, F); + let FB = new GraphEdge(F, B); // Add vertices - graph_.addVertices([A, B, C, D, E]); + graph_.addVertices([A, B, C, D, E, F]); // Add edges - graph_.addEdges([AB, BC, CD, CE, EB]); + graph_.addEdges([AB, BC, CD, CE, EB, CF, FB]); + + let from = A; + let to = D; res.send(graph_.describe()); });