blib/lib/Dreamhack/Solitaire/Medici.pm

filter: Statementstmt 98.2% 57 / 58 Branchbran 85.7% 12 / 14 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 92.7% 90 / 97 CC 12 SCAR 14.2
CC
12
Cov
94%
process
6.0
_pass
6.0
_iterations
2.1
CRAP 4.1
↑ Summary
1 package Dreamhack::Solitaire::Medici;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use base 'Dreamhack::Solitaire';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Dreamhack::Solitaire;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = "0.01";
11  
12 2 ▶sub process {
Subroutine process: called CC=6 SCAR=18.0
Pod documented
13 2 my ($self, %args) = @_;
14  
15 2 ▶ my $imax = (exists $args{'attempts'}) && ($args{'attempts'} =~ m/^[1-9]\d*$/) ? $args{'attempts'} : $self->_iterations(1+$#{$self->{'leftcards'}});
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'attempts'} && $args{'attempts'} =~ /^[1-9]\d*$/ ? : 0 2 2
Condition33%1/3
exists $args{"attempts"} and $args{"attempts"} =~ /^[1-9]\d*$/
!ll&&!rl&&r
200
MC/DC0%0/2
exists $args{"attempts"} and $args{"attempts"} =~ /^[1-9]\d*$/
exists $args{"attempts"} $args{"attempts"} =~ /^[1-9]\d*$/
Truth table33%1/3
A and B
A= exists $args{"attempts"}B= $args{"attempts"} =~ /^[1-9]\d*$/
ABresult
0X0
100
111
16  
17 2 for my $i (1..$imax) {
18  
19 2 my @layout = $self->add_rnd_layout();
20 2 my @save = @layout;
21 2 my @work = ();
22  
23 2 my $cardno = 0;
24 2 ▶ while (@layout) {
Branch: 1 branch
BranchTrueFalseTotal
if (@layout) 72 2 74
25 72 my $el = shift @layout;
26 72 push @work, $el;
27 72 @work = $self->_pass(0, \@work, $cardno++);
28 }
29  
30 2 $self->{'attempts'} = $i;
31 2 ▶ if ($#work <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#work <= 1) 1 1 2
32 1 $self->{'layout'} = \@save;
33 1 return $self;
34 }
35 1 $self->{'convolution'} = [];
36 }
37 1 return undef;
38 }
39  
40 446 ▶sub _pass {
Subroutine _pass: called CC=6 SCAR=17.9
41 446 my ($self, $offset, $work, $cardno) = @_;
42 446 my @work = @$work;
43  
44 446 ▶ if (($offset >=0) && ($#work - $offset >= 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= 0 and $#work - $offset >= 2) { } 374 72 446
Condition100%3/3
$offset >= 0 and $#work - $offset >= 2
!ll&&!rl&&r
684374
MC/DC100%2/2
$offset >= 0 and $#work - $offset >= 2
$offset >= 0 $#work - $offset >= 2
Truth table100%3/3
A and B
A= $offset >= 0B= $#work - $offset >= 2
ABresult
0X0
100
111
45 374 my ($vr, $sr) = $self->extract($work[$#work - $offset]);
46 374 my ($vl, $sl) = $self->extract($work[$#work - $offset - 2]);
47 374 ▶ if (($vl eq $vr) or ($sl eq $sr)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vl eq $vr or $sl eq $sr) { } 67 307 374
Condition100%3/3
$vl eq $vr or $sl eq $sr
l!l&&r!l&&!r
1651307
MC/DC100%2/2
$vl eq $vr or $sl eq $sr
$vl eq $vr $sl eq $sr
Truth table100%3/3
A or B
A= $vl eq $vrB= $sl eq $sr
ABresult
1X1
011
000
48 67 $work[$#work - $offset - 2] = $work[$#work - $offset - 1];
49 67 splice @work, $#work - $offset - 1, 1;
50 67 ▶ if ($cardno) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cardno) 24 43 67
51 24 push @{$self->{'convolution'}}, $cardno;
52 }
53 67 @work = $self->_pass($#work-2, \@work);
54 }
55 else {
56 307 @work = $self->_pass(--$offset, \@work);
57 }
58 }
59 else {
60 return @work
61 72 }
62 return @work
63 374 }
64  
65 2 ▶sub _iterations {
Subroutine _iterations: called CC=2 SCAR=7.2
66 2 my ($self, $cardscount) = @_;
67  
68 2 my $imax = 0;
69 2 ▶ if ($cardscount <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cardscount <= 1) { } 2 0 2
70 2 $imax = 1;
71 }
72 else {
73 0 $imax = 100_000;
74 }
75 2 return $imax
76 }
77  
78 2 1;
79 __END__
↑ Summary