mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
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:
30
Graphs/test/Kosaraju.test.js
Normal file
30
Graphs/test/Kosaraju.test.js
Normal 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]])
|
||||
})
|
||||
Reference in New Issue
Block a user