Skip to content

Commit 70af57f

Browse files
committedMay 10, 2018
Add Tarjan's algorithm.
1 parent 5f3588e commit 70af57f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
 

‎src/algorithms/graph/articulation-points/__test__/articulationPoints.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,71 @@ describe('articulationPoints', () => {
140140
vertexD,
141141
]);
142142
});
143+
144+
it('should find articulation points in yet another graph #1', () => {
145+
const vertexA = new GraphVertex('A');
146+
const vertexB = new GraphVertex('B');
147+
const vertexC = new GraphVertex('C');
148+
const vertexD = new GraphVertex('D');
149+
const vertexE = new GraphVertex('E');
150+
151+
const edgeAB = new GraphEdge(vertexA, vertexB);
152+
const edgeAC = new GraphEdge(vertexA, vertexC);
153+
const edgeBC = new GraphEdge(vertexB, vertexC);
154+
const edgeCD = new GraphEdge(vertexC, vertexD);
155+
const edgeDE = new GraphEdge(vertexD, vertexE);
156+
157+
const graph = new Graph();
158+
159+
graph
160+
.addEdge(edgeAB)
161+
.addEdge(edgeAC)
162+
.addEdge(edgeBC)
163+
.addEdge(edgeCD)
164+
.addEdge(edgeDE);
165+
166+
const articulationPointsSet = articulationPoints(graph);
167+
168+
expect(articulationPointsSet).toEqual([
169+
vertexD,
170+
vertexC,
171+
]);
172+
});
173+
174+
it('should find articulation points in yet another graph #2', () => {
175+
const vertexA = new GraphVertex('A');
176+
const vertexB = new GraphVertex('B');
177+
const vertexC = new GraphVertex('C');
178+
const vertexD = new GraphVertex('D');
179+
const vertexE = new GraphVertex('E');
180+
const vertexF = new GraphVertex('F');
181+
const vertexG = new GraphVertex('G');
182+
183+
const edgeAB = new GraphEdge(vertexA, vertexB);
184+
const edgeAC = new GraphEdge(vertexA, vertexC);
185+
const edgeBC = new GraphEdge(vertexB, vertexC);
186+
const edgeCD = new GraphEdge(vertexC, vertexD);
187+
const edgeCE = new GraphEdge(vertexC, vertexE);
188+
const edgeCF = new GraphEdge(vertexC, vertexF);
189+
const edgeEG = new GraphEdge(vertexE, vertexG);
190+
const edgeFG = new GraphEdge(vertexF, vertexG);
191+
192+
const graph = new Graph();
193+
194+
graph
195+
.addEdge(edgeAB)
196+
.addEdge(edgeAC)
197+
.addEdge(edgeBC)
198+
.addEdge(edgeCD)
199+
.addEdge(edgeCE)
200+
.addEdge(edgeCF)
201+
.addEdge(edgeEG)
202+
.addEdge(edgeFG);
203+
204+
const articulationPointsSet = articulationPoints(graph);
205+
206+
expect(articulationPointsSet).toEqual([
207+
vertexC,
208+
]);
209+
});
143210
});

0 commit comments

Comments
 (0)
Please sign in to comment.