Graph/TransitiveClosure.pm

filter: Statementstmt 100% 37 / 37 Branchbran 92.8% 13 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 93.0% 67 / 72 CC 12 SCAR 20.8
CC
12
Cov
95%
new
12.1
BEGIN
1.0
BEGIN
1.0
CRAP 8.0
« Graph/AdjacencyMap.pm ↑ Summary Graph.pm »
1 package Graph::TransitiveClosure;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # COMMENT THESE OUT FOR TESTING AND PRODUCTION.
7 # $SIG{__DIE__ } = \&Graph::__carp_confess;
8 # $SIG{__WARN__} = \&Graph::__carp_confess;
9  
10 6 ▶use base 'Graph';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Graph::TransitiveClosure::Matrix;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub _G () { Graph::_G() }
14  
15 75 ▶sub new {
Subroutine new: called CC=12 SCAR=24.9
Pod documented
16 75 my ($class, $g, %opt) = @_;
17 75 ▶ Graph::__carp_confess(__PACKAGE__."->new given non-Graph '$g'")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $g and $g->isa("Graph") 0 75 75
Condition33%1/3
ref $g and $g->isa("Graph")
!ll&&!rl&&r
0075
MC/DC0%0/2
ref $g and $g->isa("Graph")
ref $g $g->isa("Graph")
Truth table33%1/3
A and B
A= ref $gB= $g->isa("Graph")
ABresult
0X0
100
111
18 if !(ref $g and $g->isa('Graph'));
19 75 ▶ %opt = (path_vertices => 1) unless %opt;
Branch: 1 branch
BranchTrueFalseTotal
unless %opt 25 50 75
20 # No delete $opt{ attribute_name } since we need to pass it on.
21 75 ▶ my $attr = exists $opt{ attribute_name } ? $opt{ attribute_name } : Graph::_defattr();
Branch: 1 branch
BranchTrueFalseTotal
exists $opt{'attribute_name'} ? : 1 74 75
22 75 ▶ $opt{ reflexive } = 1 unless exists $opt{ reflexive };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt{"reflexive"} 69 6 75
23 my $tcg = $g->new(
24 multiedged => 0,
25 75 ▶ ($opt{ reflexive } ? (vertices => [$g->vertices]) : ()),
Branch: 1 branch
BranchTrueFalseTotal
$opt{'reflexive'} ? : 72 3 75
26 );
27 75 my $tcm = $g->_check_cache('transitive_closure_matrix', [],
28 \&_transitive_closure_matrix_compute, %opt);
29 75 my $tcm00 = $tcm->[0][0]; # 0=am, 0=bitmatrix
30 75 my $tcm01 = $tcm->[0][1]; # , 1=hash mapping v-name to the offset into dm data structures (in retval of $g->vertices)
31 75 my @edges;
32 75 for my $u ($tcm->vertices) {
33 528 my $tcm00i = $tcm00->[ $tcm01->{ $u } ];
34 528 for my $v ($tcm->vertices) {
35 18100 ▶ next if $u eq $v && ! $opt{ reflexive };
Branch: 1 branch
BranchTrueFalseTotal
if $u eq $v and not $opt{"reflexive"} 12 18088 18100
Condition100%3/3
$u eq $v and not $opt{"reflexive"}
!ll&&!rl&&r
1757251612
MC/DC100%2/2
$u eq $v and not $opt{"reflexive"}
$u eq $v not $opt{"reflexive"}
Truth table100%3/3
A and not(B)
A= $u eq $vB= not $opt{"reflexive"}
ABresult
0X0
100
111
36 18088 my $j = $tcm01->{ $v };
37 18088 ▶ push @edges, [$u, $v] if vec($tcm00i, $j, 1);
Branch: 1 branch
BranchTrueFalseTotal
if vec $tcm00i, $j, 1 8174 9914 18088
38 # $tcm->is_transitive($u, $v)
39 # $tcm->[0]->get($u, $v)
40 }
41 }
42 75 $tcg->add_edges(@edges);
43 75 $tcg->set_graph_attribute('_tcm', [ $g->[ _G ], $tcm ]);
44 75 bless $tcg, $class;
45 }
46  
47 60 ▶sub _transitive_closure_matrix_compute {
Subroutine _transitive_closure_matrix_compute: called CC=1 SCAR=0.0
48 60 Graph::TransitiveClosure::Matrix->new(@_);
49 }
50  
51 10 ▶sub is_transitive {
Subroutine is_transitive: called CC=1 SCAR=0.0
Pod documented
52 10 my $g = shift;
53 10 $g->expect_no_args(@_);
54 10 Graph::TransitiveClosure::Matrix::is_transitive($g);
55 }
56  
57 13295 ▶sub transitive_closure_matrix {
Subroutine transitive_closure_matrix: called CC=1 SCAR=0.0
Pod documented
58 13295 $_[0]->get_graph_attribute('_tcm')->[1];
59 }
60  
61 6 1;
62 __END__
« Graph/AdjacencyMap.pm ↑ Summary Graph.pm »