/
basic.t
93 lines (84 loc) · 1.83 KB
/
basic.t
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
use v6;
use Test;
use Algorithm::Tarjan;
my Algorithm::Tarjan $a .= new();
isa-ok $a, Algorithm::Tarjan, 'module loads';
my %h = (
a => <b c d e f>,
b => <g h>,
c => <i j g>,
d => (),
e => (),
f => (),
g => <k l m>,
h => (),
i => (),
j => (),
k => (),
l => (),
m => ()
);
lives-ok { $a.init( %h ) }, 'test graph, no cycles loads';
lives-ok { $a.strong-components()}, 'get strong components without dying';
is-deeply $a.strongly-connected.flat, (), 'trivial list of strong components';
%h = (
a => <b c d e f>,
b => <g h>,
c => <i j g>,
d => (),
e => (),
f => (),
g => <k l m>
);
lives-ok { $a.init( %h ) }, 'test graph, no cycles loads, but missing nodes in hash';
$a.strong-components();
is-deeply $a.strongly-connected.flat, (), 'trivial list of strong components';
is $a.find-cycles, 0, 'no cycles in graph';
%h = (
a => <b c d e f>,
b => <g h>,
c => <i j g>,
d => (),
e => (),
f => (),
g => <k l m>,
h => (),
i => (),
j => (),
k => (),
l => (),
m => ('a', )
);
$a.init( %h );
$a.strong-components();
is-deeply $a.strongly-connected.list, ['a,b,c,g,m'], 'list of strong components in graph';
is $a.find-cycles, 1, 'A cycle in graph';
%h = (
a => ('b', ),
b => ('c', ),
c => ('a', ),
d => <b c e>,
e => <d f>,
f => <c g>,
g => ('f',),
h => <e g h>
);
$a.init( %h );
$a.strong-components();
is-deeply $a.strongly-connected.list, ['a,b,c', 'f,g', 'd,e'], 'deals with graph in Wikipedia article';
is $a.find-cycles, 3, 'Three cycles in graph';
%h = (
MinModel => <a b c>,
a => <a1 b2>,
a1 => (),
b => ('b1',),
b1 => <a1 b3 b4 b5>,
b2 => <b3 b4 c>,
b3 => (),
b4 => (),
b5 => (),
c => ('c1',),
c1 => <c2 b1 a b3 b4>,
c2 => ()
);
done-testing();