Dominoes/Scoring.pm

filter: Statementstmt 48.3% 15 / 31 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 27.5% 22 / 80 CC 14 SCAR 33.3
CC
14
Cov
25%
score_for
42.0
count
30.0
bonus
30.0
CRAP 27.8
« Dominoes/Rules.pm ↑ Summary Dominoes/Boneyard.pm »
1 package Game::Dominoes::Scoring;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.04';
9 1 our @EXPORT_OK = qw(count score_for bonus MAX_COUNT);
10  
11 1 ▶use constant MAX_COUNT => 35;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub count {
Subroutine count: not called CC=5 SCAR=34.0
Pod documented
14 0 my ($layout) = @_;
15 0 ▶ die 'Game::Dominoes::Scoring: count wants a layout' unless ref $layout;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $layout 0 0 0
16 0 my $total = 0;
17 0 for my $end ($layout->ends) {
18 $total += ($end->{sole} || $end->{tile}->is_double)
19 ? $end->{tile}->pips
20 0 ▶ : $end->{face};
Branch: 1 branch
BranchTrueFalseTotal
$end->{'sole'} || $end->{'tile'}->is_double ? : 0 0 0
Condition0%0/3
$end->{"sole"} or $end->{"tile"}->is_double
l!l&&r!l&&!r
000
MC/DC0%0/2
$end->{"sole"} or $end->{"tile"}->is_double
$end->{"sole"} $end->{"tile"}->is_double
Truth table0%0/3
A or B
A= $end->{"sole"}B= $end->{"tile"}->is_double
ABresult
1X1
011
000
21 }
22 0 return $total;
23 }
24  
25 0 ▶sub score_for {
Subroutine score_for: not called CC=6 SCAR=37.4
Pod documented
26 0 my ($total, $scale) = @_;
27 0 ▶ return 0 unless defined $total && $total > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $total and $total > 0 0 0 0
Condition0%0/3
defined $total and $total > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $total and $total > 0
defined $total $total > 0
Truth table0%0/3
A and B
A= defined $totalB= $total > 0
ABresult
0X0
100
111
28 0 ▶ return 0 if $total % 5;
Branch: 1 branch
BranchTrueFalseTotal
if $total % 5 0 0 0
29 0 ▶ $scale = 1 unless defined $scale && $scale > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scale and $scale > 0 0 0 0
Condition0%0/3
defined $scale and $scale > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $scale and $scale > 0
defined $scale $scale > 0
Truth table0%0/3
A and B
A= defined $scaleB= $scale > 0
ABresult
0X0
100
111
30 0 return $total / $scale;
31 }
32  
33 0 ▶sub bonus {
Subroutine bonus: not called CC=5 SCAR=34.0
Pod documented
34 0 my ($pips, $scale) = @_;
35 0 ▶ return 0 unless defined $pips && $pips > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pips and $pips > 0 0 0 0
Condition0%0/3
defined $pips and $pips > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pips and $pips > 0
defined $pips $pips > 0
Truth table0%0/3
A and B
A= defined $pipsB= $pips > 0
ABresult
0X0
100
111
36 0 my $rounded = int(($pips + 2) / 5) * 5;
37 0 ▶ $scale = 1 unless defined $scale && $scale > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scale and $scale > 0 0 0 0
Condition0%0/3
defined $scale and $scale > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $scale and $scale > 0
defined $scale $scale > 0
Truth table0%0/3
A and B
A= defined $scaleB= $scale > 0
ABresult
0X0
100
111
38 0 return $rounded / $scale;
39 }
40  
41 1 1;
42  
43 __END__
« Dominoes/Rules.pm ↑ Summary Dominoes/Boneyard.pm »