blib/lib/Game/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
« blib/lib/Game/Dominoes/Rules.pm ↑ Summary blib/lib/Game/Dominoes/Scoring.pm »
1 package Game::Dominoes::Tile;
2  
3 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 43 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 43 our $VERSION = '0.05';
9  
10 8459969 ▶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 43 );
16  
17 has low => (
18 is => 'ro',
19 isa => Int
20 43 );
21  
22 2249 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
23 2249 my ($self) = @_;
24 2249 for my $face (qw/high low/) {
25 4497 my $v = $self->$face;
26 4497 ▶ 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 4495 4497
Condition66%2/3
defined $v and $v =~ /\A[0-6]\z/
!ll&&!rl&&r
024495
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 2247 ▶ die 'Game::Dominoes::Tile: high must not be less than low'
Branch: 1 branch
BranchTrueFalseTotal
if $self->high < $self->low 1 2246 2247
30 if $self->high < $self->low;
31 2246 return $self;
32 }
33  
34 1013 ▶sub of {
Subroutine of: called CC=4 SCAR=14.6
Pod documented
35 1013 my ($class, $a, $b) = @_;
36 1013 ▶ ($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 1002 1013
Condition50%3/6
defined $a and defined $b and $a < $b
!ll&&!rl&&r
0100211
defined $a and defined $b
!ll&&!rl&&r
001013
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 1013 return $class->new(high => $a, low => $b);
38 }
39  
40 8453942 ▶sub id {
Subroutine id: called CC=1 SCAR=0.0
Pod documented
41 8453942 my ($self) = @_;
42 8453942 return _offset($self->low) + ($self->high - $self->low) + 1;
43 }
44  
45 1206 ▶sub from_id {
Subroutine from_id: called CC=8 SCAR=23.1
Pod documented
46 1206 my ($class, $id) = @_;
47 1206 ▶ 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 1205 1206
defined $id ? : 1 0 1
Condition44%4/9
defined $id and $id =~ /\A\d+\z/ and $id >= 1 and $id <= 28
!ll&&!rl&&r
011205
defined $id and $id =~ /\A\d+\z/ and $id >= 1
!ll&&!rl&&r
001206
defined $id and $id =~ /\A\d+\z/
!ll&&!rl&&r
001206
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 1205 for my $low (reverse 0 .. 6) {
50 6027 my $offset = _offset($low);
51 6027 ▶ next if $offset >= $id;
Branch: 1 branch
BranchTrueFalseTotal
if $offset >= $id 4822 1205 6027
52 1205 return $class->new(low => $low, high => $low + ($id - $offset - 1));
53 }
54 0 die 'unreachable';
55 }
56  
57 4469332 ▶sub is_double {
Subroutine is_double: called CC=2 SCAR=6.9
Pod documented
58 4469332 ▶ return $_[0]->high == $_[0]->low ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->high == $_[0]->low ? : 673772 3795560 4469332
59 }
60  
61 673271 ▶sub pips {
Subroutine pips: called CC=1 SCAR=0.0
Pod documented
62 673271 return $_[0]->high + $_[0]->low;
63 }
64  
65 7747765 ▶sub has_face {
Subroutine has_face: called CC=4 SCAR=13.9
Pod documented
66 7747765 my ($self, $face) = @_;
67 7747765 ▶ return 0 unless defined $face;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $face 1 7747764 7747765
68 7747764 ▶ return ($self->high == $face || $self->low == $face) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->high == $face || $self->low == $face ? : 3497941 4249823 7747764
Condition100%3/3
$self->high == $face or $self->low == $face
l!l&&r!l&&!r
192301615749254249823
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 1238940 ▶sub other {
Subroutine other: called CC=4 SCAR=13.9
Pod documented
72 1238940 my ($self, $face) = @_;
73 1238940 ▶ die 'Game::Dominoes::Tile: that tile does not carry face '
Branch: 2 branches
BranchTrueFalseTotal
unless $self->has_face($face) 1 1238939 1238940
defined $face ? : 1 0 1
74 . (defined $face ? $face : 'undef')
75 unless $self->has_face($face);
76 1238939 ▶ return $self->high == $face ? $self->low : $self->high;
Branch: 1 branch
BranchTrueFalseTotal
$self->high == $face ? : 684954 553985 1238939
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 18916 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
86 18916 my ($self) = @_;
87 18916 return $self->high . '-' . $self->low;
88 }
89  
90 43 1;
91  
92 __END__
« blib/lib/Game/Dominoes/Rules.pm ↑ Summary blib/lib/Game/Dominoes/Scoring.pm »