Graph/Writer/Graph6.pm

filter: Statementstmt 41.4% 17 / 41 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 55.5% 5 / 9 Podpod n/a totaltotal 34.3% 22 / 64 SCAR 25.2
CC
5
Cov
33%
_write_graph
20.0
_has_edge_either_directed
6.0
_init
2.0
CRAP 12.4
« Graph/Graph6.pm ↑ Summary Graph/Easy/Parser/Graph6.pm »
1 # Copyright 2015, 2016, 2017 Kevin Ryde
2 #
3 # This file is part of Graph-Graph6.
4 #
5 # Graph-Graph6 is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Graph-Graph6 is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Graph-Graph6. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 # ENHANCE-ME: Maybe an append option to append to a $filename instead of
20 # re-write it. Perhaps
21  
22  
23 package Graph::Writer::Graph6;
24 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use Graph::Graph6;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Graph::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 2 ▶use vars '@ISA','$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 @ISA = ('Graph::Writer');
31 2 $VERSION = 8;
32  
33  
34 sub _init {
35 0 ▶ my ($self,%param) = @_;
Subroutine _init: not called CC=1 SCAR=6.9
36 0 $self->SUPER::_init();
37 0 %$self = (format => 'graph6',
38 %$self,
39 %param);
40 }
41  
42 # $graph is a Graph.pm object
43 # return true if there is an edge either direction between $v1 and $v2
44 sub _has_edge_either_directed {
45 0 ▶ my ($graph, $v1, $v2) = @_;
Subroutine _has_edge_either_directed: not called CC=2 SCAR=17.9
46 0 ▶ return ($graph->has_edge($v1,$v2) || $graph->has_edge($v2,$v1));
Condition0%0/3
$graph->has_edge($v1, $v2) || $graph->has_edge($v2, $v1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$graph->has_edge($v1, $v2) || $graph->has_edge($v2, $v1)
$graph->has_edge($v1, $v2) $graph->has_edge($v2, $v1)
Truth table0%0/3
A || B
A= $graph->has_edge($v1, $v2)B= $graph->has_edge($v2, $v1)
ABresult
1X1
011
000
47 }
48  
49 sub _write_graph {
50 0 ▶ my ($self, $graph, $fh) = @_;
Subroutine _write_graph: not called CC=4 SCAR=30.0
51  
52 0 my @vertices = sort $graph->vertices;
53 0 my @edge_options;
54 0 my $format = $self->{'format'};
55 0 ▶ if ($format eq 'sparse6') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'sparse6') { } 0 0 0
56 0 my @edges = $graph->edges; # [ $from_name, $to_name ]
57 ### @edges
58  
59 # as [$from,$to] numbers
60 0 my %vertex_to_num = map { $vertices[$_] => $_ } 0 .. $#vertices;
61 0 @edges = map { my $from = $vertex_to_num{$_->[0]};
62 0 my $to = $vertex_to_num{$_->[1]};
63 0 [$from, $to]
64 } @edges;
65 0 @edge_options = (edge_aref => \@edges);
66 } else {
67 0 ▶ my $has_edge_either = ($graph->is_directed && $format ne 'digraph6'
Branch: 1 branch
BranchTrueFalseTotal
$graph->is_directed && $format ne 'digraph6' ? : 0 0 0
Condition0%0/3
$graph->is_directed and $format ne "digraph6"
!ll&&!rl&&r
000
MC/DC0%0/2
$graph->is_directed and $format ne "digraph6"
$graph->is_directed $format ne "digraph6"
Truth table0%0/3
A and B
A= $graph->is_directedB= $format ne "digraph6"
ABresult
0X0
100
111
68 ? \&_has_edge_either_directed
69  
70 # graph undirected, or directed and format digraph
71 : 'has_edge');
72 @edge_options
73 = (edge_predicate => sub {
74 0 ▶ my ($from, $to) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 return $graph->$has_edge_either($vertices[$from], $vertices[$to]);
76 0 });
77 }
78  
79 Graph::Graph6::write_graph
80 (format => $format,
81 0 header => $self->{'header'},
82 fh => $fh,
83 num_vertices => scalar(@vertices),
84 @edge_options);
85 0 return 1;
86 }
87  
88 2 1;
89 __END__
« Graph/Graph6.pm ↑ Summary Graph/Easy/Parser/Graph6.pm »