algorithm: kosaraju (#1215)

* kosaraju test added

* Fixes: #1214

* Fixes: #1214

* Update package-lock.json

* Kosaraju.js exports function kosaraju rather than class
This commit is contained in:
Adrito Mukherjee
2022-10-20 20:35:24 +05:30
committed by GitHub
parent 6f9a8e4b5a
commit ce9e2946be
2 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { kosaraju } from '../Kosaraju.js'
test('Test Case 1', () => {
const graph = [
[1, 2],
[2, 3],
[3, 1],
[2, 4],
[4, 5],
[5, 6],
[6, 4]
]
const stronglyConnectedComponents = kosaraju(graph)
expect(stronglyConnectedComponents).toStrictEqual([
[1, 3, 2],
[4, 6, 5]
])
})
test('Test Case 2', () => {
const graph = [
[1, 2],
[2, 3],
[3, 1],
[2, 4],
[4, 5]
]
const stronglyConnectedComponents = kosaraju(graph)
expect(stronglyConnectedComponents).toStrictEqual([[1, 3, 2], [4], [5]])
})