Petersen.pm

filter: Statementstmt 100% 43 / 43 Branchbran 91.6% 11 / 12 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 90.4% 66 / 73 CC 11 SCAR 18.1
CC
11
Cov
95%
init
10.0
make_graph
2.0
BEGIN
1.0
CRAP 6.1
« BulgarianSolitaire.pm ↑ Summary HexGrid.pm »
1 # Copyright 2015, 2016, 2017, 2018, 2019, 2020, 2021 Kevin Ryde
2 #
3 # This file is part of Graph-Maker-Other.
4 #
5 # This file is free software; you can redistribute it and/or modify it
6 # under 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 # This file is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Graph-Maker-Other. See the file COPYING. If not, see
17 # <http://www.gnu.org/licenses/>.
18  
19 package Graph::Maker::Petersen;
20 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Graph::Maker;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use List::Util 'min';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use vars '$VERSION','@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 $VERSION = 19;
27 1 @ISA = ('Graph::Maker');
28  
29 # uncomment this to run the ### lines
30 # use Smart::Comments;
31  
32  
33 # Usage: $graph = $self->make_graph(key=>value)
34 # Create and return a graph with given key/value parameters.
35 # Parameter graph_maker is used (and removed) if given, or Graph.pm otherwise.
36 9 ▶sub make_graph {
Subroutine make_graph: called CC=2 SCAR=7.1
Pod undocumented
37 9 my ($self, %params) = @_;
38 9 ▶ my $graph_maker = delete($params{'graph_maker'}) || \&_default_graph_maker;
Condition50%1/2
delete $params{'graph_maker'} || \&Graph::Maker::Petersen::_default_graph_maker
l!l
09
MC/DC0%0/1
delete $params{'graph_maker'} || \&Graph::Maker::Petersen::_default_graph_maker
delete $params{'graph_maker'}
Truth table50%1/2
A
A= delete $params{'graph_maker'}
Aresult
11
00
39 9 return $graph_maker->(%params);
40 }
41 9 ▶sub _default_graph_maker {
Subroutine _default_graph_maker: called CC=1 SCAR=0.0
42 9 require Graph;
43 9 return Graph->new(@_);
44 }
45  
46 9 ▶sub init {
Subroutine init: called CC=10 SCAR=23.0
Pod undocumented
47 9 my ($self, %params) = @_;
48 9 my $N = delete($params{'N'});
49 9 my $K = delete($params{'K'});
50 9 ▶ if (! defined $N) { $N = 5; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $N) 1 8 9
51 9 ▶ if (! defined $K) { $K = 2; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $K) 1 8 9
52  
53 9 my $graph = $self->make_graph(%params);
54 9 ▶ $graph->set_graph_attribute (name => ($N==5 && $K==2 ? "Petersen" : "Petersen $N,$K"));
Branch: 1 branch
BranchTrueFalseTotal
$N == 5 && $K == 2 ? : 2 7 9
Condition66%2/3
$N == 5 and $K == 2
!ll&&!rl&&r
702
MC/DC50%1/2
$N == 5 and $K == 2
$N == 5 $K == 2
Truth table66%2/3
A and B
A= $N == 5B= $K == 2
ABresult
0X0
100
111
55  
56 9 ▶ if ($N) { $K = min($K%$N, (-$K)%$N); }
Branch: 1 branch
BranchTrueFalseTotal
if ($N) 9 0 9
57 ### K reduced: $K
58 ### cf N/2: $N/2
59  
60 9 $graph->add_cycle(1 .. $N); # outer cycle
61 9 foreach my $i (1 .. $N) {
62 47 $graph->add_edge($i,$i+$N); # outer to inner
63 }
64 9 ▶ foreach my $i (0 .. ($K==$N/2 ? $N/2 : $N)-1) {
Branch: 1 branch
BranchTrueFalseTotal
$K == $N / 2 ? : 4 5 9
65 39 $graph->add_edge($N+1+$i, $N+1+(($i+$K)%$N)); # inner circulant
66 }
67 9 ▶ if ($graph->is_directed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph->is_directed) 6 3 9
68 6 $graph->add_edges(map {[reverse @$_]} $graph->edges);
69 }
70 9 return $graph;
71 }
72  
73 1 Graph::Maker->add_factory_type('Petersen' => __PACKAGE__);
74 1 1;
75  
76 __END__
« BulgarianSolitaire.pm ↑ Summary HexGrid.pm »