| 1 | package Graph::Maker::Disk; | ||||||||||||||||||||||||||||||||||||||||||
| 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 constant TWO_PI => 2*3.1415926535897932384626433832795; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=17 SCAR=30.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | my $numDisks = delete($params{disks}) || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{'disks'} || 0
MC/DC0%0/1
delete $params{'disks'} || 0
delete $params{'disks'}
Truth table50%1/2
A
A= delete $params{'disks'}
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | my $numPerDisk = delete($params{init})|| 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $params{'init'} || 0
MC/DC0%0/1
delete $params{'init'} || 0
delete $params{'init'}
Truth table50%1/2
A
A= delete $params{'init'}
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my $gm = delete($params{graph_maker}); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 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
Condition33%1/3
$gm and ref $gm ne "CODE"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | $gm ||= sub { new Graph(@_); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$gm ||= sub {
"Graph"->new(@_);
}
MC/DC0%0/2
$gm ||= sub {
"Graph"->new(@_);
}
$gm
sub {
"Graph"->new(@_);
}
Truth table33%1/3
A ||= B
A= $gmB= sub {
"Graph"->new(@_);
}
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | croak "init must be defined and greater than 1 or equal to 0\n" unless defined $numPerDisk && ($numPerDisk >= 2 && $numPerDisk != 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $numPerDisk and ($numPerDisk >= 2 and $numPerDisk != 0)
$numPerDisk >= 2 and $numPerDisk != 0
MC/DC0%0/3
defined $numPerDisk and ($numPerDisk >= 2 and $numPerDisk != 0)
defined $numPerDisk
$numPerDisk >= 2
$numPerDisk != 0
Truth table25%1/4
A and B and C
A= defined $numPerDiskB= $numPerDisk >= 2C= $numPerDisk != 0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | my $g = $gm->(%params); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | $g->set_vertex_attribute(1, 'pos', [0, 0]); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | $g->add_edges(1, $_, ($g->is_directed() ? ($_, 1) : ())) for (2..$numPerDisk+1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | my $v = 2; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | for my $i(1..$numDisks) | |||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | my $thetaDel = TWO_PI / $numPerDisk; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | my $theta = 0; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | if($numPerDisk > 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | $g->add_cycle($v..$v+$numPerDisk-1); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | $g->add_cycle(reverse $v..$v+$numPerDisk-1) unless $g->is_undirected(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | for my $j(0..$numPerDisk-1) | |||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 18 | $g->set_vertex_attribute($v, 'pos', [$i * cos($theta), $i * sin($theta)]); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 18 | ▶ | if($i < $numDisks) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | $g->add_edges($v, $v+$numPerDisk+$j, $v, $v+$numPerDisk+$j+1); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | $g->add_edges($v+$numPerDisk+$j, $v, $v+$numPerDisk+$j+1, $v) unless $g->is_undirected(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 18 | $v++; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | $theta += $thetaDel; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | $numPerDisk *= 2; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | return $g; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | Graph::Maker->add_factory_type( 'disk' => __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||