blib/lib/Game/Backgammon/Turn.pm

filter: Statementstmt 77.7% 35 / 45 Branchbran 100% 12 / 12 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 70.0% 7 / 10 Podpod 100% 7 / 7 totaltotal 82.1% 69 / 84 CC 11 SCAR 14.1
CC
11
Cov
83%
notation
7.0
pips_used
6.0
is_doubles
3.0
CRAP 4.1
« blib/lib/Game/Backgammon/Dice.pm ↑ Summary blib/lib/Game/Backgammon/Error.pm »
1 package Game::Backgammon::Turn;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 29 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 29 our $VERSION = '0.05';
9  
10 has player => (
11 is => 'ro',
12 isa => Str
13 29 );
14  
15 has [qw/dice moves/] => (
16 is => 'ro',
17 isa => ArrayRef,
18 default => []
19 29 );
20  
21 10 ▶sub is_doubles {
Subroutine is_doubles: called CC=3 SCAR=11.1
Pod documented
22 10 my $d = $_[0]->dice;
23 10 ▶ return (@$d >= 2 && $d->[0] == $d->[1]) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$d >= 2 && $d->[0] == $d->[1] ? : 2 8 10
Condition66%2/3
@$d >= 2 and $d->[0] == $d->[1]
!ll&&!rl&&r
082
MC/DC50%1/2
@$d >= 2 and $d->[0] == $d->[1]
@$d >= 2 $d->[0] == $d->[1]
Truth table66%2/3
A and B
A= @$d >= 2B= $d->[0] == $d->[1]
ABresult
0X0
100
111
24 }
25  
26 0 ▶sub with_move {
Subroutine with_move: not called CC=1 SCAR=6.9
Pod documented
27 0 my ($self, $move) = @_;
28 return ref($self)->new(
29 player => $self->player,
30 0 dice => [ @{ $self->dice } ],
31 0 moves => [ @{ $self->moves }, $move ]
32 );
33 }
34  
35 0 ▶sub pips_used {
Subroutine pips_used: not called CC=2 SCAR=17.9
Pod documented
36 0 my ($self) = @_;
37 0 my $n = 0;
38 0 $n += $_->die for @{ $self->moves };
39 0 return $n;
40 }
41  
42 10382 ▶sub is_forfeit { return scalar @{ $_[0]->moves } ? 0 : 1 }
Subroutine is_forfeit: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$_[0]->moves;} ? : 10350 32 10382
43  
44 47836 ▶sub notation {
Subroutine notation: called CC=7 SCAR=19.5
Pod documented
45 47836 my ($self) = @_;
46 47836 ▶ return '(no play)' unless @{ $self->moves };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->moves;} 286 47550 47836
47 47550 my @out;
48 47550 my ($run, $count) = (undef, 0);
49 47550 for my $m (@{ $self->moves }, undef) {
50 158171 ▶ if ($run && $run->same_as($m)) { $count++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($run and $run->same_as($m)) 1786 156385 158171
Condition100%3/3
$run and $run->same_as($m)
!ll&&!rl&&r
475501088351786
MC/DC100%2/2
$run and $run->same_as($m)
$run $run->same_as($m)
Truth table100%3/3
A and B
A= $runB= $run->same_as($m)
ABresult
0X0
100
111
51 156385 ▶ if ($run) { push @out, $run->notation . ($count > 1 ? "($count)" : '') }
Branch: 2 branches
BranchTrueFalseTotal
if ($run) 108835 47550 156385
$count > 1 ? : 1419 107416 108835
52 156385 ($run, $count) = ($m, 1);
53 }
54 47550 return join ' ', @out;
55 }
56  
57 1350242 ▶sub key {
Subroutine key: called CC=1 SCAR=0.0
Pod documented
58 1350242 my ($self) = @_;
59 1350242 return join ',', sort map { $_->notation } @{ $self->moves };
60 }
61  
62 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
63 0 return $_[0]->notation;
64 }
65  
66 29 1;
67  
68 __END__
« blib/lib/Game/Backgammon/Dice.pm ↑ Summary blib/lib/Game/Backgammon/Error.pm »