Maker/SmallWorldWS.pm

filter: Statementstmt 100% 48 / 48 Branchbran 88.8% 16 / 18 Conditioncond 46.6% 7 / 15 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 80.8% 80 / 99 CC 19 SCAR 27.3
CC
19
Cov
88%
init
20.7
__ANON__
1.1
BEGIN
1.0
CRAP 15.4
« Maker/Regular.pm ↑ Summary Maker/Disk.pm »
1 package Graph::Maker::SmallWorldWS;
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 random_uniform_integer/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 2 our $VERSION = '0.01';
11
12 sub init
13 3 ▶{
Subroutine init: called CC=19 SCAR=30.3
Pod undocumented
14 3 my ($self, %params) = @_;
15
16 3 ▶ my $n = delete($params{N}) || 0;
Condition50%1/2
delete $params{'N'} || 0
l!l
30
MC/DC0%0/1
delete $params{'N'} || 0
delete $params{'N'}
Truth table50%1/2
A
A= delete $params{'N'}
Aresult
11
00
17 3 ▶ my $k = delete($params{K}) || 0;
Condition50%1/2
delete $params{'K'} || 0
l!l
30
MC/DC0%0/1
delete $params{'K'} || 0
delete $params{'K'}
Truth table50%1/2
A
A= delete $params{'K'}
Aresult
11
00
18 3 ▶ my $p = delete($params{PR}) || 0;
Condition50%1/2
delete $params{'PR'} || 0
l!l
30
MC/DC0%0/1
delete $params{'PR'} || 0
delete $params{'PR'}
Truth table50%1/2
A
A= delete $params{'PR'}
Aresult
11
00
19 3 my $a = delete($params{keep_edges});
20 3 my $gm = delete($params{graph_maker});
21 3 ▶ 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 3 3
Condition33%1/3
$gm and ref $gm ne "CODE"
!ll&&!rl&&r
300
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 3 ▶ $gm ||= sub { new Graph(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$gm ||= sub { "Graph"->new(@_); }
l!l&&r!l&&!r
030
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 3 ▶ $k = $n if $k > $n;
Branch: 1 branch
BranchTrueFalseTotal
if $k > $n 0 3 3
25
26 3 my $g = $gm->(%params);
27 3 my @v = (1..$n);
28
29 # Connect initial ring
30 3 foreach my $v(@v)
31 {
32 300 for my $w(1..int($k/2 + .5))
33 {
34 400 my $j = $v + $w;
35 400 ▶ $j = ($j % $n) if $j > $n;
Branch: 1 branch
BranchTrueFalseTotal
if $j > $n 5 395 400
36 400 $g->add_edge($v, $j);
37 400 ▶ $g->add_edge($j, $v) unless $g->is_undirected();
Branch: 1 branch
BranchTrueFalseTotal
unless $g->is_undirected 100 300 400
38 }
39 }
40
41 # Rewire
42 3 foreach my $e($g->edges())
43 {
44 500 ▶ if(random_uniform() < $p)
Branch: 1 branch
BranchTrueFalseTotal
if (random_uniform() < $p) 160 340 500
45 {
46 160 my $w = random_uniform_integer(1, 1, $n);
47 160 ▶ $w = random_uniform_integer(1, 1, $n) until $w != $e->[0] && !$g->has_edge($e->[0], $w);
Branch: 1 branch
BranchTrueFalseTotal
$w != $e->[0] and not $g->has_edge($e->[0], $w) or do { $w = random_uniform_integer(1, 1, $n) } 160 14 174
Condition66%2/3
$w != $e->[0] and not $g->has_edge($e->[0], $w)
!ll&&!rl&&r
014160
MC/DC50%1/2
$w != $e->[0] and not $g->has_edge($e->[0], $w)
$w != $e->[0] not $g->has_edge($e->[0], $w)
Truth table66%2/3
A and not(B)
A= $w != $e->[0]B= not $g->has_edge($e->[0], $w)
ABresult
0X0
100
111
48
49 160 ▶ $g->delete_edge(@$e) unless $a;
Branch: 1 branch
BranchTrueFalseTotal
unless $a 8 152 160
50 160 ▶ $g->delete_edge(reverse @$e) unless $a;
Branch: 1 branch
BranchTrueFalseTotal
unless $a 8 152 160
51 160 $g->add_edge($e->[0], $w);
52 160 ▶ $g->add_edge($w, $e->[0]) unless $g->is_undirected();
Branch: 1 branch
BranchTrueFalseTotal
unless $g->is_undirected 104 56 160
53 }
54 }
55
56 3 return $g;
57 }
58
59 2 Graph::Maker->add_factory_type( 'small_world_ws' => __PACKAGE__ );
60
61 2 1;
62
63 __DATA__
« Maker/Regular.pm ↑ Summary Maker/Disk.pm »