MoreUtils/Smooth.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 60.0% 12 / 20 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 75.6% 56 / 74 CC 14 SCAR 26.3
CC
14
Cov
79%
smooth
18.4
BEGIN
1.0
BEGIN
1.0
CRAP 13.8
« MoreUtils/Replace.pm ↑ Summary MoreUtils/Line.pm »
1 package Graph::MoreUtils::Smooth;
2  
3 # ABSTRACT: Generate smoothed graphs
4 9 our $VERSION = '0.3.0'; # VERSION
5  
6 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶use Graph::MoreUtils::Smooth::Intermediate;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Graph::Undirected;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub smooth
14 3 ▶{
Subroutine smooth: called CC=14 SCAR=29.1
Pod undocumented
15 3 my( $graph ) = @_;
16  
17 3 ▶ if( !blessed $graph || !$graph->isa( Graph::Undirected:: ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($graph) and $graph->isa("Graph::Undirected")) 0 3 3
Condition33%1/3
builtin::blessed($graph) and $graph->isa("Graph::Undirected")
!ll&&!rl&&r
003
MC/DC0%0/2
builtin::blessed($graph) and $graph->isa("Graph::Undirected")
builtin::blessed($graph) $graph->isa("Graph::Undirected")
Truth table33%1/3
A and B
A= builtin::blessed($graph)B= $graph->isa("Graph::Undirected")
ABresult
0X0
100
111
18 0 die 'only Graph::Undirected and its derivatives are accepted' . "\n";
19 }
20  
21 3 for ($graph->vertices) {
22 55 ▶ next unless $graph->degree( $_ ) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $graph->degree($_) == 2 4 51 55
23 51 my( $a, $b ) = sort $graph->neighbours( $_ );
24  
25 # do not reduce cycles of three vertices:
26 51 ▶ next if $graph->has_edge( $a, $b );
Branch: 1 branch
BranchTrueFalseTotal
if $graph->has_edge($a, $b) 3 48 51
27  
28 48 my $intermediate;
29 48 ▶ if( $graph->has_edge_attribute( $a, $_, 'intermediate' ) &&
Branch: 3 branches
BranchTrueFalseTotal
if ($graph->has_edge_attribute($a, $_, 'intermediate') and $graph->has_edge_attribute($b, $_, 'intermediate')) { } 0 48 48
elsif ($graph->has_edge_attribute($a, $_, 'intermediate')) { } 23 25 48
elsif ($graph->has_edge_attribute($b, $_, 'intermediate')) { } 23 2 25
Condition66%2/3
$graph->has_edge_attribute($a, $_, "intermediate") and $graph->has_edge_attribute($b, $_, "intermediate")
!ll&&!rl&&r
25230
MC/DC0%0/2
$graph->has_edge_attribute($a, $_, "intermediate") and $graph->has_edge_attribute($b, $_, "intermediate")
$graph->has_edge_attribute($a, $_, "intermediate") $graph->has_edge_attribute($b, $_, "intermediate")
Truth table66%2/3
A and B
A= $graph->has_edge_attribute($a, $_, "intermediate")B= $graph->has_edge_attribute($b, $_, "intermediate")
ABresult
0X0
100
111
30 $graph->has_edge_attribute( $b, $_, 'intermediate' ) ) {
31 0 ▶ $intermediate = Graph::MoreUtils::Smooth::Intermediate->new(
Branch: 2 branches
BranchTrueFalseTotal
$_ lt $a ? : 0 0 0
$_ gt $b ? : 0 0 0
32 $_ lt $a
33 ? $graph->get_edge_attribute( $a, $_, 'intermediate' )->reverse
34 : $graph->get_edge_attribute( $a, $_, 'intermediate' ),
35 $_,
36 $_ gt $b
37 ? $graph->get_edge_attribute( $b, $_, 'intermediate' )->reverse
38 : $graph->get_edge_attribute( $b, $_, 'intermediate' ) );
39 } elsif( $graph->has_edge_attribute( $a, $_, 'intermediate' ) ) {
40 23 $intermediate = $graph->get_edge_attribute( $a, $_, 'intermediate' );
41 23 ▶ $intermediate->reverse if $a gt $_; # getting natural order
Branch: 1 branch
BranchTrueFalseTotal
if $a gt $_ 0 23 23
42 23 push @$intermediate, $_;
43 } elsif( $graph->has_edge_attribute( $b, $_, 'intermediate' ) ) {
44 23 $intermediate = $graph->get_edge_attribute( $b, $_, 'intermediate' );
45 23 ▶ $intermediate->reverse if $_ gt $b; # getting natural order
Branch: 1 branch
BranchTrueFalseTotal
if $_ gt $b 0 23 23
46 23 unshift @$intermediate, $_;
47 } else {
48 2 $intermediate = Graph::MoreUtils::Smooth::Intermediate->new( $_ );
49 }
50  
51 48 $graph->delete_vertex( $_ );
52 48 $graph->set_edge_attribute( $a, $b, 'intermediate', $intermediate );
53 }
54  
55 3 return $graph;
56 }
57  
58 9 1;
« MoreUtils/Replace.pm ↑ Summary MoreUtils/Line.pm »