FoldedHypercube.pm

filter: Statementstmt 100% 30 / 30 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 95.3% 41 / 43 CC 5 SCAR 11.0
CC
5
Cov
97%
init
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« Beineke.pm ↑ Summary Crown.pm »
1 # Copyright 2019, 2020, 2021, 2022 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::FoldedHypercube;
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 Graph::Maker::Hypercube;
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 23 ▶sub init {
Subroutine init: called CC=5 SCAR=16.1
Pod undocumented
34 23 my ($self, %params) = @_;
35 23 my $N = delete($params{'N'});
36  
37 # decrement to make N-1 half cube
38 23 ▶ if ($N) { $N--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($N) 20 3 23
39 23 my $graph = Graph::Maker->new('hypercube', N => $N, %params);
40  
41 # Graph::Maker::Hypercube in its version 0.01 has N=0 as empty instead
42 # of 2^0=1 vertices. Ensure vertex 1 in this case.
43 23 $graph->add_vertex(1);
44  
45 23 ▶ if ($N > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($N > 1) 14 9 23
46 # 1..8 is edges from=1..4 to 5..8 with end=9
47 14 ▶ my $add = $graph->is_directed ? 'add_cycle' : 'add_edge';
Branch: 1 branch
BranchTrueFalseTotal
$graph->is_directed ? : 0 14 14
48 14 my $end = (1 << $N) + 1;
49 14 foreach my $from (1 .. ($end>>1)) {
50 ### edge: [$from, $end - $from]
51 256 $graph->$add ($from, $end - $from);
52 }
53 }
54 ### edges: $graph->edges
55 23 return $graph;
56 }
57  
58 1 Graph::Maker->add_factory_type('folded_hypercube' => __PACKAGE__);
59 1 1;
60  
61 __END__
« Beineke.pm ↑ Summary Crown.pm »