Crown.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Circulant.pm ↑ Summary FibonacciTree.pm »
1 # Copyright 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  
20 package Graph::Maker::Crown;
21 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Graph::Maker;
Subroutine BEGIN: called CC=1 SCAR=2.6
24  
25 use vars '$VERSION','@ISA';
26 $VERSION = 17;
27 @ISA = ('Graph::Maker');
28  
29  
30 sub _default_graph_maker {
31 require Graph;
32 Graph->new(@_);
33 }
34 sub _make_graph {
35 my ($params) = @_;
36 my $graph_maker = delete($params->{'graph_maker'}) || \&_default_graph_maker;
37 return $graph_maker->(%$params);
38 }
39  
40 sub init {
41 my ($self, %params) = @_;
42  
43 my $N = delete $params{'N'};
44 my $graph = _make_graph(\%params);
45 $graph->set_graph_attribute (name => "Crown $N");
46  
47 my $add_edge = ($graph->is_directed ? 'add_cycle' : 'add_edge');
48 foreach my $u (1 .. $N) {
49 $graph->add_vertex ($u);
50 $graph->add_vertex ($u+$N);
51 foreach my $v (1 .. $N) {
52 if ($u != $v) {
53 $graph->$add_edge($u, $v+$N);
54 }
55 }
56 }
57 return $graph;
58 }
59  
60 Graph::Maker->add_factory_type('crown' => __PACKAGE__);
61 1;
62  
63 __END__
« Circulant.pm ↑ Summary FibonacciTree.pm »