MoreUtils/Line.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 85.7% 12 / 14 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 87.8% 72 / 82 CC 18 SCAR 26.2
CC
18
Cov
91%
line
18.7
BEGIN
1.0
BEGIN
1.0
CRAP 13.8
« MoreUtils/Smooth.pm ↑ Summary MoreUtils/SSSR.pm »
1 package Graph::MoreUtils::Line;
2  
3 # ABSTRACT: Generate line 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 Algorithm::Combinatorics qw( combinations );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Graph::MoreUtils::Line::SelfLoopVertex;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Graph::Undirected;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub line
16 10 ▶{
Subroutine line: called CC=18 SCAR=29.3
Pod undocumented
17 10 my( $graph, $options ) = @_;
18  
19 10 ▶ if( !blessed $graph || !$graph->isa( Graph:: ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($graph) and $graph->isa("Graph")) 0 10 10
Condition33%1/3
builtin::blessed($graph) and $graph->isa("Graph")
!ll&&!rl&&r
0010
MC/DC0%0/2
builtin::blessed($graph) and $graph->isa("Graph")
builtin::blessed($graph) $graph->isa("Graph")
Truth table33%1/3
A and B
A= builtin::blessed($graph)B= $graph->isa("Graph")
ABresult
0X0
100
111
20 0 die 'only Graph and its derivatives are accepted' . "\n";
21 }
22  
23 10 ▶ $options = {} unless $options;
Branch: 1 branch
BranchTrueFalseTotal
unless $options 8 2 10
24  
25 10 my $line_graph = Graph->new( directed => $graph->is_directed,
26 refvertexed => 1 );
27  
28 # Add the edges as vertices to the edge graph
29 10 ▶ if( $graph->is_multiedged ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph->is_multiedged) { } 4 6 10
30 4 for my $unique_edge ($graph->unique_edges) {
31 4 for my $edge ($graph->get_multiedge_ids( @$unique_edge )) {
32 9 ▶ my $edge_vertex = $graph->get_edge_attributes_by_id( @$unique_edge, $edge ) || {};
Condition50%1/2
$graph->get_edge_attributes_by_id(@$unique_edge, $edge) || {}
l!l
90
MC/DC0%0/1
$graph->get_edge_attributes_by_id(@$unique_edge, $edge) || {}
$graph->get_edge_attributes_by_id(@$unique_edge, $edge)
Truth table50%1/2
A
A= $graph->get_edge_attributes_by_id(@$unique_edge, $edge)
Aresult
11
00
33 9 $line_graph->add_path( $unique_edge->[0], $edge_vertex, $unique_edge->[1] );
34 }
35 }
36 } else {
37 6 for my $edge ($graph->edges) {
38 22 ▶ my $edge_vertex = $graph->get_edge_attributes( @$edge ) || {};
Condition100%2/2
$graph->get_edge_attributes(@$edge) || {}
l!l
1012
MC/DC100%1/1
$graph->get_edge_attributes(@$edge) || {}
$graph->get_edge_attributes(@$edge)
Truth table100%2/2
A
A= $graph->get_edge_attributes(@$edge)
Aresult
11
00
39 22 $line_graph->add_path( $edge->[0], $edge_vertex, $edge->[1] );
40 }
41 }
42  
43 # Interconnect edge vertices which share the original vertex
44 10 for my $vertex ($graph->vertices) {
45 26 ▶ if( $graph->is_directed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph->is_directed) { } 6 20 26
46 # TODO: Check for self-loops
47 6 for my $in ($line_graph->predecessors( $vertex )) {
48 12 for my $out ($line_graph->successors( $vertex )) {
49 24 $line_graph->set_edge_attribute( $in,
50 $out,
51 'original_vertex',
52 $vertex );
53 }
54 }
55 } else {
56 20 ▶ next unless $line_graph->degree( $vertex );
Branch: 1 branch
BranchTrueFalseTotal
unless $line_graph->degree($vertex) 0 20 20
57 20 ▶ if( $line_graph->degree( $vertex ) > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line_graph->degree($vertex) > 1) { } 13 7 20
elsif ($options->{'loop_end_vertices'}) { } 2 5 7
58 13 for my $edge (combinations( [ $line_graph->neighbours( $vertex ) ], 2 )) {
59 17 $line_graph->set_edge_attribute( @$edge, 'original_vertex', $vertex );
60 }
61 } elsif( $options->{loop_end_vertices} ) {
62 2 $line_graph->set_edge_attribute( $line_graph->neighbours( $vertex ),
63 Graph::MoreUtils::Line::SelfLoopVertex->new,
64 'original_vertex',
65 $vertex );
66 }
67 }
68 }
69  
70 10 $line_graph->delete_vertices( $graph->vertices );
71  
72 10 return $line_graph;
73 }
74  
75 9 1;
« MoreUtils/Smooth.pm ↑ Summary MoreUtils/SSSR.pm »