blib/lib/Game/Shogi/Result.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 12 / 12 Conditioncond 87.5% 14 / 16 MC/DCmcdc 77.7% 7 / 9 Subroutinesub 100% 8 / 8 Podpod 66.6% 2 / 3 totaltotal 93.7% 75 / 80 CC 13 SCAR 17.8
CC
13
Cov
97%
BUILD
10.0
loser
3.0
is_draw
2.0
CRAP 5.9
« blib/lib/Game/Shogi/Notation.pm ↑ Summary blib/lib/Game/Shogi/Bot.pm »
1 package Game::Shogi::Result;
2  
3 7 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 our $VERSION = '0.01';
11  
12 7 my %HOW = map { $_ => 1 } qw(mate no_move resign sennichite perpetual_check impasse_declared cap);
13  
14 7 has how => (is => 'ro');
15  
16 7 has winner => (is => 'ro');
17  
18 7 has ply => (is => 'ro', default => 0);
19  
20 64 ▶sub BUILD {
Subroutine BUILD: called CC=10 SCAR=23.1
Pod undocumented
21 64 my ($self) = @_;
22 64 my $how = $self->how;
23 Carp::croak("Game::Shogi::Result: '" . ($how // 'undef') . "' is not how a game ends")
24 64 ▶ unless defined $how && $HOW{$how};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $how and $HOW{$how} 2 62 64
Condition100%5/5
defined $how and $HOW{$how}
!ll&&!rl&&r
1162
$how // "undef"
l!l
11
MC/DC100%2/2
defined $how and $HOW{$how}
defined $how $HOW{$how}
MC/DC100%1/1
$how // "undef"
$how
Truth table100%3/3
A and B
A= defined $howB= $HOW{$how}
ABresult
0X0
100
111
Truth table100%2/2
A
A= $how
Aresult
11
00
25 62 my $winner = $self->winner;
26 62 ▶ Carp::croak("Game::Shogi::Result: the winner is 'b', 'w' or undef, not '$winner'")
Branch: 1 branch
BranchTrueFalseTotal
if defined $winner and $winner ne "b" and $winner ne "w" 1 61 62
Condition100%6/6
defined $winner and $winner ne "b" and $winner ne "w"
!ll&&!rl&&r
40211
defined $winner and $winner ne "b"
!ll&&!rl&&r
152522
MC/DC100%3/3
defined $winner and $winner ne "b" and $winner ne "w"
defined $winner $winner ne "b" $winner ne "w"
Truth table100%4/4
A and B and C
A= defined $winnerB= $winner ne "b"C= $winner ne "w"
ABCresult
0XX0
10X0
1100
1111
27 if defined $winner && $winner ne 'b' && $winner ne 'w';
28 61 my $ply = $self->ply;
29 61 ▶ Carp::croak("Game::Shogi::Result: the ply is a count, not '" . ($ply // 'undef') . "'")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ply and $ply =~ /\A[0-9]+\z/u 2 59 61
Condition60%3/5
defined $ply and $ply =~ /\A[0-9]+\z/u
!ll&&!rl&&r
0259
$ply // "undef"
l!l
20
MC/DC50%1/2
defined $ply and $ply =~ /\A[0-9]+\z/u
defined $ply $ply =~ /\A[0-9]+\z/u
MC/DC0%0/1
$ply // "undef"
$ply
Truth table66%2/3
A and B
A= defined $plyB= $ply =~ /\A[0-9]+\z/u
ABresult
0X0
100
111
Truth table50%1/2
A
A= $ply
Aresult
11
00
30 unless defined $ply && $ply =~ /\A[0-9]+\z/;
31 59 return;
32 }
33  
34 4 ▶sub loser {
Subroutine loser: called CC=3 SCAR=11.0
Pod documented
35 4 my $w = $_[0]->winner;
36 4 ▶ return defined $w ? ($w eq 'b' ? 'w' : 'b') : undef;
Branch: 2 branches
BranchTrueFalseTotal
defined $w ? : 3 1 4
$w eq 'b' ? : 1 2 3
37 }
38  
39 9 ▶sub is_draw { defined $_[0]->winner ? 0 : 1 }
Subroutine is_draw: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->winner ? : 4 5 9
40  
41 7 1;
42  
43 __END__
« blib/lib/Game/Shogi/Notation.pm ↑ Summary blib/lib/Game/Shogi/Bot.pm »