Dominoes/Tile.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 85.7% 24 / 28 Conditioncond 57.1% 12 / 21 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 100% 14 / 14 Podpod 90.0% 9 / 10 totaltotal 83.8% 109 / 130 CC 24 SCAR 15.6
CC
24
Cov
85%
from_id
10.1
BUILD
5.0
of
4.3
CRAP 4.7
« Dominoes/Rules.pm ↑ Summary Dominoes/Scoring.pm »
1 package Game::Dominoes::Tile;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 our $VERSION = '0.03';
9  
10 6304571 ▶sub _offset { my ($l) = @_; return 7 * $l - ($l * ($l - 1)) / 2 }
Subroutine _offset: called CC=1 SCAR=0.0
11  
12 has high => (
13 is => 'ro',
14 isa => Int
15 17 );
16  
17 has low => (
18 is => 'ro',
19 isa => Int
20 17 );
21  
22 772 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
23 772 my ($self) = @_;
24 772 for my $face (qw/high low/) {
25 1543 my $v = $self->$face;
26 1543 ▶ die "Game::Dominoes::Tile: $face must be a face from 0 to 6"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and $v =~ /\A[0-6]\z/ 2 1541 1543
Condition66%2/3
defined $v and $v =~ /\A[0-6]\z/
!ll&&!rl&&r
021541
MC/DC50%1/2
defined $v and $v =~ /\A[0-6]\z/
defined $v $v =~ /\A[0-6]\z/
Truth table66%2/3
A and B
A= defined $vB= $v =~ /\A[0-6]\z/
ABresult
0X0
100
111
27 unless defined $v && $v =~ /\A[0-6]\z/;
28 }
29 770 ▶ die 'Game::Dominoes::Tile: high must not be less than low'
Branch: 1 branch
BranchTrueFalseTotal
if $self->high < $self->low 1 769 770
30 if $self->high < $self->low;
31 769 return $self;
32 }
33  
34 264 ▶sub of {
Subroutine of: called CC=4 SCAR=14.6
Pod documented
35 264 my ($class, $a, $b) = @_;
36 264 ▶ ($a, $b) = ($b, $a) if defined $a && defined $b && $a < $b;
Branch: 1 branch
BranchTrueFalseTotal
if defined $a and defined $b and $a < $b 11 253 264
Condition50%3/6
defined $a and defined $b and $a < $b
!ll&&!rl&&r
025311
defined $a and defined $b
!ll&&!rl&&r
00264
MC/DC33%1/3
defined $a and defined $b and $a < $b
defined $a defined $b $a < $b
Truth table50%2/4
A and B and C
A= defined $aB= defined $bC= $a < $b
ABCresult
0XX0
10X0
1100
1111
37 264 return $class->new(high => $a, low => $b);
38 }
39  
40 6302184 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
41 6302184 my ($self) = @_;
42 6302184 return _offset($self->low) + ($self->high - $self->low) + 1;
43 }
44  
45 478 ▶sub from_id {
Subroutine from_id: called CC=8 SCAR=23.1
Pod documented
46 478 my ($class, $id) = @_;
47 478 ▶ die "Game::Dominoes::Tile: no tile has id " . (defined $id ? $id : 'undef')
Branch: 2 branches
BranchTrueFalseTotal
unless defined $id and $id =~ /\A\d+\z/ and $id >= 1 and $id <= 28 1 477 478
defined $id ? : 1 0 1
Condition44%4/9
defined $id and $id =~ /\A\d+\z/ and $id >= 1 and $id <= 28
!ll&&!rl&&r
01477
defined $id and $id =~ /\A\d+\z/ and $id >= 1
!ll&&!rl&&r
00478
defined $id and $id =~ /\A\d+\z/
!ll&&!rl&&r
00478
MC/DC25%1/4
defined $id and $id =~ /\A\d+\z/ and $id >= 1 and $id <= 28
defined $id $id =~ /\A\d+\z/ $id >= 1 $id <= 28
Truth table40%2/5
A and B and C and D
A= defined $idB= $id =~ /\A\d+\z/C= $id >= 1D= $id <= 28
ABCDresult
0XXX0
10XX0
110X0
11100
11111
48 unless defined $id && $id =~ /\A\d+\z/ && $id >= 1 && $id <= 28;
49 477 for my $low (reverse 0 .. 6) {
50 2387 my $offset = _offset($low);
51 2387 ▶ next if $offset >= $id;
Branch: 1 branch
BranchTrueFalseTotal
if $offset >= $id 1910 477 2387
52 477 return $class->new(low => $low, high => $low + ($id - $offset - 1));
53 }
54 0 die 'unreachable';
55 }
56  
57 3071004 ▶sub is_double {
Subroutine is_double: called CC=2 SCAR=6.9
Pod documented
58 3071004 ▶ return $_[0]->high == $_[0]->low ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->high == $_[0]->low ? : 464411 2606593 3071004
59 }
60  
61 469500 ▶sub pips {
Subroutine pips: called CC=1 SCAR=0.0
Pod documented
62 469500 return $_[0]->high + $_[0]->low;
63 }
64  
65 5550587 ▶sub has_face {
Subroutine has_face: called CC=4 SCAR=13.9
Pod documented
66 5550587 my ($self, $face) = @_;
67 5550587 ▶ return 0 unless defined $face;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $face 1 5550586 5550587
68 5550586 ▶ return ($self->high == $face || $self->low == $face) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->high == $face || $self->low == $face ? : 2487976 3062610 5550586
Condition100%3/3
$self->high == $face or $self->low == $face
l!l&&r!l&&!r
135069311372833062610
MC/DC100%2/2
$self->high == $face or $self->low == $face
$self->high == $face $self->low == $face
Truth table100%3/3
A or B
A= $self->high == $faceB= $self->low == $face
ABresult
1X1
011
000
69 }
70  
71 872951 ▶sub other {
Subroutine other: called CC=4 SCAR=13.9
Pod documented
72 872951 my ($self, $face) = @_;
73 872951 ▶ die 'Game::Dominoes::Tile: that tile does not carry face '
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_face($face) 1 872950 872951
defined $face ? : 1 0 1
74 . (defined $face ? $face : 'undef')
75 unless $self->has_face($face);
76 872950 ▶ return $self->high == $face ? $self->low : $self->high;
Branch: 1 branch
BranchTrueFalseTotal
$self->high == $face ? : 476974 395976 872950
77 }
78  
79 1 ▶sub equals {
Subroutine equals: called CC=3 SCAR=11.7
Pod documented
80 1 my ($self, $other) = @_;
81 1 ▶ return 0 unless ref $other;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $other 0 1 1
82 1 ▶ return $self->id == $other->id ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->id == $other->id ? : 1 0 1
83 }
84  
85 9800 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
86 9800 my ($self) = @_;
87 9800 return $self->high . '-' . $self->low;
88 }
89  
90 17 1;
91  
92 __END__
« Dominoes/Rules.pm ↑ Summary Dominoes/Scoring.pm »