-
-
Notifications
You must be signed in to change notification settings - Fork 408
/
Copy pathkosajaru.test.ts
94 lines (79 loc) · 2.56 KB
/
kosajaru.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { kosajaru } from '../kosajaru'
describe('kosajaru', () => {
it('it should return no sccs for empty graph', () => {
expect(kosajaru([])).toStrictEqual([])
})
it('it should return one scc for graph with one element', () => {
expect(kosajaru([[]])).toStrictEqual([[0]])
})
it('it should return one scc for graph with element that points to itself', () => {
expect(kosajaru([[0]])).toStrictEqual([[0]])
})
it('it should return one scc for two element graph with cycle', () => {
expect(kosajaru([[1], [0]])).toStrictEqual([[0, 1]])
})
it('should return one scc for each element for straight line', () => {
expect(kosajaru([[1], [2], [3], []])).toStrictEqual([[0], [1], [2], [3]])
})
it('should return sccs for straight line with backedge in middle', () => {
expect(kosajaru([[1], [2], [3, 0], []])).toStrictEqual([[0, 2, 1], [3]])
})
it('should return sccs for straight line with backedge from end to middle', () => {
expect(kosajaru([[1], [2], [3], [1]])).toStrictEqual([[0], [1, 3, 2]])
})
it('should return scc for each element for graph with no edges', () => {
expect(kosajaru([[], [], [], []])).toStrictEqual([[3], [2], [1], [0]])
})
it('should return sccs disconnected graph', () => {
expect(kosajaru([[1, 2], [0, 2], [0, 1], []])).toStrictEqual([
[3],
[0, 1, 2]
])
})
it('should return sccs disconnected graph', () => {
expect(kosajaru([[1, 2], [0, 2], [0, 1], [4], [5], [3]])).toStrictEqual([
[3, 5, 4],
[0, 1, 2]
])
})
it('should return single scc', () => {
expect(kosajaru([[1], [2], [3], [0, 4], [3]])).toStrictEqual([
[0, 3, 2, 1, 4]
])
})
it('should return one scc for complete connected graph', () => {
const input = [
[1, 2, 3, 4],
[0, 2, 3, 4],
[0, 1, 3, 4],
[0, 1, 2, 4],
[0, 1, 2, 3]
]
expect(kosajaru(input)).toStrictEqual([[0, 1, 2, 3, 4]])
})
it('should return sccs', () => {
const input = [[1], [2], [0, 3], [4], []]
expect(kosajaru(input)).toStrictEqual([[0, 2, 1], [3], [4]])
})
it('should return sccs', () => {
const input = [
[1],
[2],
[0, 3, 4],
[0],
[5],
[6, 7],
[2, 4],
[8],
[5, 9],
[5]
]
const expected = [[0, 2, 1, 6, 5, 4, 8, 7, 9, 3]]
expect(kosajaru(input)).toStrictEqual(expected)
})
it('should return sccs', () => {
const input = [[1], [0, 2], [0, 3], [4], [5, 7], [6], [4, 7], []]
const expected = [[0, 1, 2], [3], [4, 6, 5], [7]]
expect(kosajaru(input)).toStrictEqual(expected)
})
})