Maker/BalancedTree.pm

filter: Statementstmt 100% 45 / 45 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 75.9% 63 / 83 CC 14 SCAR 24.6
CC
14
Cov
84%
init
16.2
__ANON__
1.1
BEGIN
1.0
CRAP 11.7
« Maker/Uniform.pm ↑ Summary Maker/Barbell.pm »
1 package Graph::Maker::BalancedTree;
2
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base qw/Graph::Maker/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 2 our $VERSION = '0.01';
10
11 sub init
12 2 ▶{
Subroutine init: called CC=14 SCAR=27.9
Pod undocumented
13 2 my ($self, %params) = @_;
14
15 2 my $b = delete($params{fan_out});
16 2 my $h = delete($params{height});
17 2 my $gm = delete($params{graph_maker});
18 2 ▶ croak "graph_maker must be a reference to a function that creates a Graph.\n" if $gm && ref($gm) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $gm and ref $gm ne "CODE" 0 2 2
Condition33%1/3
$gm and ref $gm ne "CODE"
!ll&&!rl&&r
200
MC/DC0%0/2
$gm and ref $gm ne "CODE"
$gm ref $gm ne "CODE"
Truth table33%1/3
A and B
A= $gmB= ref $gm ne "CODE"
ABresult
0X0
100
111
19 2 ▶ $gm ||= sub { new Graph(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$gm ||= sub { "Graph"->new(@_); }
l!l&&r!l&&!r
020
MC/DC0%0/2
$gm ||= sub { "Graph"->new(@_); }
$gm sub { "Graph"->new(@_); }
Truth table33%1/3
A ||= B
A= $gmB= sub { "Graph"->new(@_); }
ABresult
1X1
011
000
20
21 2 ▶ croak "fan_out must be defined and at least 2\n" unless defined $b && $b >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b and $b >= 2 0 2 2
Condition33%1/3
defined $b and $b >= 2
!ll&&!rl&&r
002
MC/DC0%0/2
defined $b and $b >= 2
defined $b $b >= 2
Truth table33%1/3
A and B
A= defined $bB= $b >= 2
ABresult
0X0
100
111
22 2 ▶ croak "h must be defined and positive\n" unless defined $h && $h >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h and $h >= 1 0 2 2
Condition33%1/3
defined $h and $h >= 1
!ll&&!rl&&r
002
MC/DC0%0/2
defined $h and $h >= 1
defined $h $h >= 1
Truth table33%1/3
A and B
A= defined $hB= $h >= 1
ABresult
0X0
100
111
23
24 2 my $g = $gm->(%params);
25
26 # First handle the root
27 2 my $v = 2; # the vertex number
28 2 my @newLeaves; # the set of new leaves
29 2 for (1..$b)
30 {
31 6 push(@newLeaves, $v);
32 6 $g->add_edge(1, $v);
33 6 ▶ $g->add_edge($v, 1) unless $g->is_undirected();
Branch: 1 branch
BranchTrueFalseTotal
unless $g->is_undirected 3 3 6
34 6 $v++;
35 }
36
37 # Now the rest
38 2 for (2..$h-1)
39 {
40 2 my @leaves = @newLeaves;
41 2 @newLeaves = ();
42 2 foreach my $l(@leaves)
43 {
44 6 for (1..$b)
45 {
46 18 push(@newLeaves, $v);
47 18 $g->add_edge($l, $v);
48 18 ▶ $g->add_edge($v, $l) unless $g->is_undirected();
Branch: 1 branch
BranchTrueFalseTotal
unless $g->is_undirected 9 9 18
49 18 $v++;
50 }
51 }
52 }
53
54 2 return $g;
55 }
56
57 2 Graph::Maker->add_factory_type( 'balanced_tree' => __PACKAGE__ );
58
59 2 1;
60
61
62 __DATA__
« Maker/Uniform.pm ↑ Summary Maker/Barbell.pm »