Maker/Regular.pm

filter: Statementstmt 100% 55 / 55 Branchbran 84.6% 22 / 26 Conditioncond 62.5% 10 / 16 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 85.3% 99 / 116 CC 22 SCAR 28.8
CC
22
Cov
90%
init
23.1
__ANON__
1.1
BEGIN
1.0
CRAP 17.8
« Maker/Bipartite.pm ↑ Summary Maker/SmallWorldWS.pm »
1 package Graph::Maker::Regular;
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 2 ▶use Math::Random qw/random_uniform_integer/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 2 our $VERSION = '0.01';
11
12 sub init
13 4 ▶{
Subroutine init: called CC=22 SCAR=31.4
Pod undocumented
14 4 my ($self, %params) = @_;
15
16 4 ▶ my $n = delete($params{N}) || 0;
Condition50%1/2
delete $params{'N'} || 0
l!l
40
MC/DC0%0/1
delete $params{'N'} || 0
delete $params{'N'}
Truth table50%1/2
A
A= delete $params{'N'}
Aresult
11
00
17 4 ▶ my $k = delete($params{K}) || 0;
Condition50%1/2
delete $params{'K'} || 0
l!l
40
MC/DC0%0/1
delete $params{'K'} || 0
delete $params{'K'}
Truth table50%1/2
A
A= delete $params{'K'}
Aresult
11
00
18 4 ▶ $k = $n if $k > $n;
Branch: 1 branch
BranchTrueFalseTotal
if $k > $n 0 4 4
19 4 ▶ croak "N*K (" . ($n*$k) . ") must be even\n" if ($n*$k) & 1;
Branch: 1 branch
BranchTrueFalseTotal
if $n * $k & 1 0 4 4
20 4 my $gm = delete($params{graph_maker});
21 4 ▶ 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 4 4
Condition33%1/3
$gm and ref $gm ne "CODE"
!ll&&!rl&&r
400
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
22 4 ▶ $gm ||= sub { new Graph(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$gm ||= sub { "Graph"->new(@_); }
l!l&&r!l&&!r
040
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
23
24 4 my $g = $gm->(%params);
25
26 4 my @a = (1..$n);
27 4 my %c;
28
29 4 ▶ while(@a > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@a > 1) 51 3 54
30 {
31 51 my @e = random_uniform_integer(2, 0, @a-1);
32 51 ▶ if($e[0] != $e[1] && !$g->has_edge(@a[@e]))
Branch: 1 branch
BranchTrueFalseTotal
if ($e[0] != $e[1] and not $g->has_edge(@a[@e])) { } 26 25 51
Condition100%3/3
$e[0] != $e[1] and not $g->has_edge(@a[@e])
!ll&&!rl&&r
21426
MC/DC100%2/2
$e[0] != $e[1] and not $g->has_edge(@a[@e])
$e[0] != $e[1] not $g->has_edge(@a[@e])
Truth table100%3/3
A and not(B)
A= $e[0] != $e[1]B= not $g->has_edge(@a[@e])
ABresult
0X0
100
111
33 {
34 26 $g->add_edge(@a[@e]);
35 26 ▶ $g->add_edge(reverse @a[@e]) unless $g->is_undirected();
Branch: 1 branch
BranchTrueFalseTotal
unless $g->is_undirected 12 14 26
36 26 $c{$a[$e[0]]}++;
37 26 $c{$a[$e[1]]}++;
38 #print "\tAdded @a[@e]\t[@a]\n";
39 26 ▶ if($c{$a[$e[0]]} >= $k)
Branch: 1 branch
BranchTrueFalseTotal
if ($c{$a[$e[0]]} >= $k) 10 16 26
40 {
41 #print "\tRemoving $c{$a[$e[0]]} $a[$e[0]]\n";
42 10 splice(@a, $e[0], 1);
43 10 ▶ $e[1]-- if $e[1] > $e[0];
Branch: 1 branch
BranchTrueFalseTotal
if $e[1] > $e[0] 6 4 10
44 }
45 26 ▶ splice(@a, $e[1], 1) if $c{$a[$e[1]]} >= $k;
Branch: 1 branch
BranchTrueFalseTotal
if $c{$a[$e[1]]} >= $k 9 17 26
46 #print "\t\t\t[@a]\n";
47 }
48 else
49 {
50 #print "\twarnings...$a[$e[0]] $a[$e[1]]\n";
51 25 my $b = 0;
52 25 foreach my $u(@a)
53 {
54 50 ▶ last if $b;
Branch: 1 branch
BranchTrueFalseTotal
if $b 24 26 50
55 26 foreach my $v(@a)
56 {
57 52 ▶ do {$b = 1; last} if $u != $v && !$g->has_edge($u, $v);
Branch: 1 branch
BranchTrueFalseTotal
if ($u != $v and not $g->has_edge($u, $v)) 24 28 52
Condition100%3/3
$u != $v and not $g->has_edge($u, $v)
!ll&&!rl&&r
26224
MC/DC100%2/2
$u != $v and not $g->has_edge($u, $v)
$u != $v not $g->has_edge($u, $v)
Truth table100%3/3
A and not(B)
A= $u != $vB= not $g->has_edge($u, $v)
ABresult
0X0
100
111
58 }
59 }
60 25 ▶ next if $b;
Branch: 1 branch
BranchTrueFalseTotal
if $b 24 1 25
61 1 croak "Could not form the requested graph...\n";
62 }
63 }
64
65 3 ▶ croak "Could not form the requested graph...\n" if @a;
Branch: 1 branch
BranchTrueFalseTotal
if @a 0 3 3
66
67 3 return $g;
68 }
69
70 2 Graph::Maker->add_factory_type( 'regular' => __PACKAGE__ );
71
72 2 1;
73
74 __DATA__
« Maker/Bipartite.pm ↑ Summary Maker/SmallWorldWS.pm »