blib/lib/Game/Merrills/Result.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 28 / 28 Conditioncond 100% 21 / 21 MC/DCmcdc 100% 12 / 12 Subroutinesub 100% 9 / 9 Podpod 80.0% 4 / 5 totaltotal 99.1% 116 / 117 CC 22 SCAR 20.6
CC
22
Cov
100%
BUILD
13.0
stringify
7.0
loser
3.0
CRAP 7.9
« blib/lib/Game/Merrills/Notation.pm ↑ Summary blib/lib/Game/Merrills/Rules.pm »
1 package Game::Merrills::Result;
2  
3 80 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 80 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 80 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 80 our $VERSION = '0.02';
9  
10 80 our (@REASONS, %REASON);
11  
12 80 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 80 @REASONS = qw/few blocked repetition no_mill agreement resign timeout/;
14 80 %REASON = map { $_ => 1 } @REASONS;
15 }
16  
17 has winner => (
18 is => 'ro'
19 80 );
20  
21 has reason => (
22 is => 'ro',
23 isa => Str
24 80 );
25  
26 362 ▶sub BUILD {
Subroutine BUILD: called CC=13 SCAR=25.6
Pod undocumented
27 362 my ($self) = @_;
28 362 my $reason = $self->reason;
29 die 'reason must be one of ' . join(', ', @REASONS) . ', got '
30 . (defined $reason ? "'$reason'" : 'undef')
31 362 ▶ unless defined $reason && $REASON{$reason};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $reason and $Game::Merrills::Result::REASON{$reason} 2 360 362
defined $reason ? : 1 1 2
Condition100%3/3
defined $reason and $Game::Merrills::Result::REASON{$reason}
!ll&&!rl&&r
11360
MC/DC100%2/2
defined $reason and $Game::Merrills::Result::REASON{$reason}
defined $reason $Game::Merrills::Result::REASON{$reason}
Truth table100%3/3
A and B
A= defined $reasonB= $Game::Merrills::Result::REASON{$reason}
ABresult
0X0
100
111
32 360 my $winner = $self->winner;
33 360 ▶ die "winner must be white, black or undef for a draw, got '$winner'"
Branch: 1 branch
BranchTrueFalseTotal
if defined $winner and $winner ne "white" and $winner ne "black" 1 359 360
Condition100%6/6
defined $winner and $winner ne "white" and $winner ne "black"
!ll&&!rl&&r
2191401
defined $winner and $winner ne "white"
!ll&&!rl&&r
23196141
MC/DC100%3/3
defined $winner and $winner ne "white" and $winner ne "black"
defined $winner $winner ne "white" $winner ne "black"
Truth table100%4/4
A and B and C
A= defined $winnerB= $winner ne "white"C= $winner ne "black"
ABCresult
0XX0
10X0
1100
1111
34 if defined $winner && $winner ne 'white' && $winner ne 'black';
35 359 ▶ my $drawn = $reason eq 'repetition' || $reason eq 'no_mill' || $reason eq 'agreement';
Condition100%6/6
$reason eq 'repetition' || $reason eq 'no_mill' || $reason eq 'agreement'
l!l&&r!l&&!r
166337
$reason eq "repetition" or $reason eq "no_mill"
l!l&&r!l&&!r
115343
MC/DC100%3/3
$reason eq 'repetition' || $reason eq 'no_mill' || $reason eq 'agreement'
$reason eq "repetition" $reason eq "no_mill" $reason eq 'agreement'
Truth table100%4/4
A or B || C
A= $reason eq "repetition"B= $reason eq "no_mill"C= $reason eq 'agreement'
ABCresult
1XX1
01X1
0011
0000
36 359 ▶ die "a game that ends by $reason is a draw and has no winner"
Branch: 1 branch
BranchTrueFalseTotal
if $drawn and defined $winner 3 356 359
Condition100%3/3
$drawn and defined $winner
!ll&&!rl&&r
337193
MC/DC100%2/2
$drawn and defined $winner
$drawn defined $winner
Truth table100%3/3
A and B
A= $drawnB= defined $winner
ABresult
0X0
100
111
37 if $drawn && defined $winner;
38 356 ▶ die "a game that ends by $reason has a winner"
Branch: 1 branch
BranchTrueFalseTotal
unless $drawn or defined $winner 4 352 356
Condition100%3/3
$drawn or defined $winner
l!l&&r!l&&!r
193334
MC/DC100%2/2
$drawn or defined $winner
$drawn defined $winner
Truth table100%3/3
A or B
A= $drawnB= defined $winner
ABresult
1X1
011
000
39 if !$drawn && !defined $winner;
40 352 return $self;
41 }
42  
43 1 ▶sub reasons {
Subroutine reasons: called CC=1 SCAR=0.0
Pod documented
44 1 return @REASONS;
45 }
46  
47 73 ▶sub is_draw {
Subroutine is_draw: called CC=2 SCAR=6.9
Pod documented
48 73 ▶ return defined $_[0]->winner ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->winner ? : 65 8 73
49 }
50  
51 40 ▶sub loser {
Subroutine loser: called CC=3 SCAR=11.0
Pod documented
52 40 my ($self) = @_;
53 40 ▶ return undef if $self->is_draw;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_draw 1 39 40
54 39 ▶ return $self->winner eq 'white' ? 'black' : 'white';
Branch: 1 branch
BranchTrueFalseTotal
$self->winner eq 'white' ? : 19 20 39
55 }
56  
57 40 ▶sub stringify {
Subroutine stringify: called CC=7 SCAR=19.5
Pod documented
58 40 my ($self) = @_;
59 40 my $reason = $self->reason;
60 40 ▶ return 'Draw: agreed' if $reason eq 'agreement';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "agreement" 4 36 40
61 36 ▶ return 'Draw: the same position three times' if $reason eq 'repetition';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "repetition" 1 35 36
62 35 ▶ return 'Draw: too long without a mill' if $reason eq 'no_mill';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "no_mill" 1 34 35
63 34 my $loser = ucfirst $self->loser;
64 34 my $winner = ucfirst $self->winner;
65 34 ▶ return "$winner wins: $loser has fewer than three men" if $reason eq 'few';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "few" 15 19 34
66 19 ▶ return "$winner wins: $loser has no move" if $reason eq 'blocked';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "blocked" 5 14 19
67 14 ▶ return "$winner wins: $loser resigned" if $reason eq 'resign';
Branch: 1 branch
BranchTrueFalseTotal
if $reason eq "resign" 12 2 14
68 2 return "$winner wins: $loser ran out of time";
69 }
70  
71 80 1;
72  
73 __END__
« blib/lib/Game/Merrills/Notation.pm ↑ Summary blib/lib/Game/Merrills/Rules.pm »