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
« Backgammon/Dice.pm ↑ Summary Backgammon/Error.pm »
1 package Game::Backgammon::Turn;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 our $VERSION = '0.04';
9  
10 has player => (
11 is => 'ro',
12 isa => Str
13 11 );
14  
15 has [qw/dice moves/] => (
16 is => 'ro',
17 isa => ArrayRef,
18 default => []
19 11 );
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 10345 ▶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;} ? : 10313 32 10345
43  
44 46870 ▶sub notation {
Subroutine notation: called CC=7 SCAR=19.5
Pod documented
45 46870 my ($self) = @_;
46 46870 ▶ return '(no play)' unless @{ $self->moves };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->moves;} 286 46584 46870
47 46584 my @out;
48 46584 my ($run, $count) = (undef, 0);
49 46584 for my $m (@{ $self->moves }, undef) {
50 154041 ▶ if ($run && $run->same_as($m)) { $count++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($run and $run->same_as($m)) 1320 152721 154041
Condition100%3/3
$run and $run->same_as($m)
!ll&&!rl&&r
465841061371320
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 152721 ▶ if ($run) { push @out, $run->notation . ($count > 1 ? "($count)" : '') }
Branch: 2 branches
BranchTrueFalseTotal
if ($run) 106137 46584 152721
$count > 1 ? : 1047 105090 106137
52 152721 ($run, $count) = ($m, 1);
53 }
54 46584 return join ' ', @out;
55 }
56  
57 1343720 ▶sub key {
Subroutine key: called CC=1 SCAR=0.0
Pod documented
58 1343720 my ($self) = @_;
59 1343720 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 11 1;
67  
68 __END__
« Backgammon/Dice.pm ↑ Summary Backgammon/Error.pm »