blib/lib/Game/Checkers/Result.pm

filter: Statementstmt 92.5% 37 / 40 Branchbran 66.6% 20 / 30 Conditioncond 66.6% 6 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 8 / 8 Podpod 80.0% 4 / 5 totaltotal 77.3% 75 / 97 CC 19 SCAR 18.4
CC
19
Cov
80%
stringify
9.7
BUILD
8.8
loser
3.0
CRAP 6.3
« blib/lib/Game/Checkers.pm ↑ Summary blib/lib/Game/Checkers/Squares.pm »
1 package Game::Checkers::Result;
2  
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 30 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 30 our $VERSION = '0.04';
9  
10 30 our %REASON = (
11 no_moves => 1,
12 resign => 1,
13 repetition => 1,
14 no_progress => 1,
15 agreement => 1,
16 timeout => 1,
17 );
18  
19 has winner => (
20 is => 'ro'
21 30 );
22  
23 has reason => (
24 is => 'ro',
25 isa => Str
26 30 );
27  
28 44 ▶sub BUILD {
Subroutine BUILD: called CC=7 SCAR=21.8
Pod undocumented
29 44 my ($self) = @_;
30 44 my $reason = $self->reason;
31 die "reason must be one of " . join(', ', sort keys %REASON) . ", got "
32 . (defined $reason ? "'$reason'" : 'undef')
33 44 ▶ unless defined $reason && $REASON{$reason};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $reason and $Game::Checkers::Result::REASON{$reason} 0 44 44
defined $reason ? : 0 0 0
Condition33%1/3
defined $reason and $Game::Checkers::Result::REASON{$reason}
!ll&&!rl&&r
0044
MC/DC0%0/2
defined $reason and $Game::Checkers::Result::REASON{$reason}
defined $reason $Game::Checkers::Result::REASON{$reason}
Truth table33%1/3
A and B
A= defined $reasonB= $Game::Checkers::Result::REASON{$reason}
ABresult
0X0
100
111
34 44 my $winner = $self->winner;
35 44 ▶ die "winner must be black, white or undef for a draw, got '$winner'"
Branch: 1 branch
BranchTrueFalseTotal
if defined $winner and $winner ne "black" and $winner ne "white" 0 44 44
Condition83%5/6
defined $winner and $winner ne "black" and $winner ne "white"
!ll&&!rl&&r
31130
defined $winner and $winner ne "black"
!ll&&!rl&&r
121913
MC/DC0%0/3
defined $winner and $winner ne "black" and $winner ne "white"
defined $winner $winner ne "black" $winner ne "white"
Truth table75%3/4
A and B and C
A= defined $winnerB= $winner ne "black"C= $winner ne "white"
ABCresult
0XX0
10X0
1100
1111
36 if defined $winner && $winner ne 'black' && $winner ne 'white';
37 44 return $self;
38 }
39  
40 46 ▶sub is_draw {
Subroutine is_draw: called CC=2 SCAR=6.9
Pod documented
41 46 ▶ return defined $_[0]->winner ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->winner ? : 32 14 46
42 }
43  
44 10 ▶sub loser {
Subroutine loser: called CC=3 SCAR=11.1
Pod documented
45 10 my ($self) = @_;
46 10 ▶ return undef if $self->is_draw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_draw 0 10 10
47 10 ▶ return $self->winner eq 'black' ? 'white' : 'black';
Branch: 1 branch
BranchTrueFalseTotal
$self->winner eq 'black' ? : 3 7 10
48 }
49  
50 22 ▶sub pdn {
Subroutine pdn: called CC=3 SCAR=11.0
Pod documented
51 22 my ($self) = @_;
52 22 ▶ return '1/2-1/2' if $self->is_draw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_draw 10 12 22
53 12 ▶ return $self->winner eq 'white' ? '1-0' : '0-1';
Branch: 1 branch
BranchTrueFalseTotal
$self->winner eq 'white' ? : 7 5 12
54 }
55  
56 12 ▶sub stringify {
Subroutine stringify: called CC=8 SCAR=22.7
Pod documented
57 12 my ($self) = @_;
58 12 my $reason = $self->reason;
59 12 ▶ if ($self->is_draw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_draw) 2 10 12
60 2 ▶ return 'Draw: agreed' if $reason eq 'agreement';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "agreement" 1 1 2
61 1 ▶ return 'Draw: threefold repetition' if $reason eq 'repetition';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "repetition" 0 1 1
62 1 ▶ return 'Draw: forty moves without progress' if $reason eq 'no_progress';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "no_progress" 1 0 1
63 0 return 'Draw';
64 }
65 10 my $loser = ucfirst $self->loser;
66 10 my $winner = ucfirst $self->winner;
67 10 ▶ return "$winner wins: $loser has no move" if $reason eq 'no_moves';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "no_moves" 6 4 10
68 4 ▶ return "$winner wins: $loser resigned" if $reason eq 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "resign" 4 0 4
69 0 ▶ return "$winner wins: $loser ran out of time" if $reason eq 'timeout';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "timeout" 0 0 0
70 0 return "$winner wins";
71 }
72  
73 30 1;
74  
75 __END__
« blib/lib/Game/Checkers.pm ↑ Summary blib/lib/Game/Checkers/Squares.pm »