blib/lib/Game/Checkers/Result.pm

filter: Statementstmt 85.0% 34 / 40 Branchbran 46.6% 14 / 30 Conditioncond 66.6% 6 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 8 / 8 Podpod 80.0% 4 / 5 totaltotal 68.0% 66 / 97 CC 19 SCAR 22.9
CC
19
Cov
68%
stringify
21.3
BUILD
8.8
loser
3.0
CRAP 9.9
« blib/lib/Game/Checkers/Rules.pm ↑ Summary blib/lib/Game/Checkers/Board.pm »
1 package Game::Checkers::Result;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 27 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 27 our $VERSION = '0.03';
9  
10 27 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 27 );
22  
23 has reason => (
24 is => 'ro',
25 isa => Str
26 27 );
27  
28 26 ▶sub BUILD {
Subroutine BUILD: called CC=7 SCAR=21.8
Pod undocumented
29 26 my ($self) = @_;
30 26 my $reason = $self->reason;
31 die "reason must be one of " . join(', ', sort keys %REASON) . ", got "
32 . (defined $reason ? "'$reason'" : 'undef')
33 26 ▶ unless defined $reason && $REASON{$reason};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $reason and $Game::Checkers::Result::REASON{$reason} 0 26 26
defined $reason ? : 0 0 0
Condition33%1/3
defined $reason and $Game::Checkers::Result::REASON{$reason}
!ll&&!rl&&r
0026
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 26 my $winner = $self->winner;
35 26 ▶ 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 26 26
Condition83%5/6
defined $winner and $winner ne "black" and $winner ne "white"
!ll&&!rl&&r
1880
defined $winner and $winner ne "black"
!ll&&!rl&&r
5138
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 26 return $self;
38 }
39  
40 21 ▶sub is_draw {
Subroutine is_draw: called CC=2 SCAR=6.9
Pod documented
41 21 ▶ return defined $_[0]->winner ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->winner ? : 16 5 21
42 }
43  
44 7 ▶sub loser {
Subroutine loser: called CC=3 SCAR=11.1
Pod documented
45 7 my ($self) = @_;
46 7 ▶ return undef if $self->is_draw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_draw 0 7 7
47 7 ▶ return $self->winner eq 'black' ? 'white' : 'black';
Branch: 1 branch
BranchTrueFalseTotal
$self->winner eq 'black' ? : 3 4 7
48 }
49  
50 5 ▶sub pdn {
Subroutine pdn: called CC=3 SCAR=11.1
Pod documented
51 5 my ($self) = @_;
52 5 ▶ return '1/2-1/2' if $self->is_draw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_draw 3 2 5
53 2 ▶ return $self->winner eq 'white' ? '1-0' : '0-1';
Branch: 1 branch
BranchTrueFalseTotal
$self->winner eq 'white' ? : 2 0 2
54 }
55  
56 7 ▶sub stringify {
Subroutine stringify: called CC=8 SCAR=30.6
Pod documented
57 7 my ($self) = @_;
58 7 my $reason = $self->reason;
59 7 ▶ if ($self->is_draw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_draw) 0 7 7
60 0 ▶ return 'Draw: agreed' if $reason eq 'agreement';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "agreement" 0 0 0
61 0 ▶ return 'Draw: threefold repetition' if $reason eq 'repetition';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "repetition" 0 0 0
62 0 ▶ return 'Draw: forty moves without progress' if $reason eq 'no_progress';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "no_progress" 0 0 0
63 0 return 'Draw';
64 }
65 7 my $loser = ucfirst $self->loser;
66 7 my $winner = ucfirst $self->winner;
67 7 ▶ return "$winner wins: $loser has no move" if $reason eq 'no_moves';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "no_moves" 4 3 7
68 3 ▶ return "$winner wins: $loser resigned" if $reason eq 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "resign" 3 0 3
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 27 1;
74  
75 __END__
« blib/lib/Game/Checkers/Rules.pm ↑ Summary blib/lib/Game/Checkers/Board.pm »