TwindragonAreaTree.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 10 / 10 Conditioncond 75.0% 6 / 8 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 93.6% 74 / 79 CC 11 SCAR 17.7
CC
11
Cov
97%
init
10.0
_make_graph
2.0
BEGIN
1.0
CRAP 5.8
« HexGrid.pm ↑ Summary BiStar.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::TwindragonAreaTree;
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 Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Graph::Maker;
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 51 ▶sub _default_graph_maker {
Subroutine _default_graph_maker: called CC=1 SCAR=0.0
34 51 require Graph;
35 51 Graph->new(@_);
36 }
37 51 ▶sub _make_graph {
Subroutine _make_graph: called CC=2 SCAR=7.1
38 51 my ($params) = @_;
39 51 ▶ my $graph_maker = delete($params->{'graph_maker'}) || \&_default_graph_maker;
Condition50%1/2
delete $params->{'graph_maker'} || \&Graph::Maker::TwindragonAreaTree::_default_graph_maker
l!l
051
MC/DC0%0/1
delete $params->{'graph_maker'} || \&Graph::Maker::TwindragonAreaTree::_default_graph_maker
delete $params->{'graph_maker'}
Truth table50%1/2
A
A= delete $params->{'graph_maker'}
Aresult
11
00
40 51 return $graph_maker->(%$params);
41 }
42 247 ▶sub _add_edge_reverse {
Subroutine _add_edge_reverse: called CC=1 SCAR=0.0
43 247 my ($graph, $u, $v) = @_;
44 247 $graph->add_edge($v,$u); # reverse
45 }
46 1 my %add_edge_method = (smaller => \&_add_edge_reverse,
47 bigger => 'add_edge',
48 both => 'add_cycle');
49  
50 51 ▶sub init {
Subroutine init: called CC=10 SCAR=23.0
Pod undocumented
51 51 my ($self, %params) = @_;
52  
53 51 ▶ my $level = delete($params{level}) || 0;
Condition100%2/2
delete $params{'level'} || 0
l!l
447
MC/DC100%1/1
delete $params{'level'} || 0
delete $params{'level'}
Truth table100%2/2
A
A= delete $params{'level'}
Aresult
11
00
54 51 ▶ my $direction_type = delete($params{'direction_type'}) || 'both';
Condition100%2/2
delete $params{'direction_type'} || 'both'
l!l
1635
MC/DC100%1/1
delete $params{'direction_type'} || 'both'
delete $params{'direction_type'}
Truth table100%2/2
A
A= delete $params{'direction_type'}
Aresult
11
00
55 ### $level
56  
57 51 my $graph = _make_graph(\%params);
58 51 $graph->set_graph_attribute(name => "Twindragon Area Tree $level");
59 51 $graph->add_vertex(0);
60 my $add_edge = ($graph->is_undirected ? 'add_edge'
61 51 ▶ : ($add_edge_method{$direction_type}
Branch: 1 branch
BranchTrueFalseTotal
$graph->is_undirected ? : 17 34 51
Condition50%1/2
$add_edge_method{$direction_type} or croak("Unrecognised direction_type ", $direction_type)
l!l
340
MC/DC0%0/1
$add_edge_method{$direction_type} or croak("Unrecognised direction_type ", $direction_type)
$add_edge_method{$direction_type}
Truth table50%1/2
A
A= $add_edge_method{$direction_type}
Aresult
11
00
62 || croak "Unrecognised direction_type ",$direction_type));
63  
64 51 V: foreach my $v (0 .. 2**$level-1) {
65 # ...1 edge from ...0
66 1537 ▶ if ($v & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v & 1) 765 772 1537
67 765 my $from = $v ^ 1;
68 765 $graph->$add_edge($from, $v); # smaller to bigger
69 }
70  
71 # ...10 11...11
72 # \-----/ zero or more low 1 bits
73 # edge to
74 # ...01 00...00
75 #
76 1537 my $bit = 1;
77 1537 for (my $pos = 1; ; $pos++) {
78 2979 ▶ $pos < $level or next V;
Branch: 1 branch
BranchTrueFalseTotal
$pos < $level or next V 2884 95 2979
79 2884 ▶ $v & $bit or last;
Branch: 1 branch
BranchTrueFalseTotal
$v & $bit or last 1442 1442 2884
80 1442 $bit <<= 1;
81 }
82 1442 $bit <<= 1;
83 1442 ▶ if ($v & $bit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v & $bit) 721 721 1442
84 721 my $from = $v-$bit+1;
85 721 $graph->$add_edge($from, $v); # smaller to bigger
86 }
87 }
88 51 return $graph;
89 }
90  
91 1 Graph::Maker->add_factory_type('twindragon_area_tree' => __PACKAGE__);
92 1 1;
93 __END__
« HexGrid.pm ↑ Summary BiStar.pm »