blib/lib/Game/Fanorona/Result.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 12 / 12 Conditioncond 100% 16 / 16 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 9 / 9 Podpod 75.0% 3 / 4 totaltotal 98.8% 84 / 85 CC 13 SCAR 17.3
CC
13
Cov
100%
BUILD
10.0
loser
3.0
is_draw
2.0
CRAP 5.7
« blib/lib/Game/Fanorona/Bot.pm ↑ Summary blib/lib/Game/Fanorona.pm »
1 package Game::Fanorona::Result;
2  
3 26 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 26 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 26 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 26 our $VERSION = '0.02';
11  
12 26 my %WON = map { $_ => 1 } qw(stones no_moves resign);
13 26 my %DRAWN = map { $_ => 1 } qw(repetition quiet ply_cap agreement);
14  
15 26 has winner => (is => 'ro');
16  
17 26 has how => (is => 'ro');
18  
19 26 has position => (is => 'ro');
20  
21 26 has moves => (is => 'ro', default => 0);
22  
23 382 ▶sub BUILD {
Subroutine BUILD: called CC=10 SCAR=23.0
Pod undocumented
24 382 my ($self) = @_;
25 382 my ($how, $winner) = ($self->how, $self->winner);
26 Carp::croak("Game::Fanorona::Result: '" . ($how // 'undef') . "' is not a way a game ends")
27 382 ▶ unless defined $how && ($WON{$how} || $DRAWN{$how});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $how and $WON{$how} || $DRAWN{$how} 2 380 382
Condition100%8/8
defined $how and $WON{$how} || $DRAWN{$how}
!ll&&!rl&&r
11380
$WON{$how} or $DRAWN{$how}
l!l&&r!l&&!r
339411
$how // "undef"
l!l
11
MC/DC100%3/3
defined $how and $WON{$how} || $DRAWN{$how}
defined $how $WON{$how} $DRAWN{$how}
MC/DC100%1/1
$how // "undef"
$how
Truth table100%4/4
A and B or C
A= defined $howB= $WON{$how}C= $DRAWN{$how}
ABCresult
0XX0
1000
11X1
1011
Truth table100%2/2
A
A= $how
Aresult
11
00
28 380 ▶ if ($WON{$how}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WON{$how}) { } 339 41 380
29 339 ▶ Carp::croak("Game::Fanorona::Result: a game ended by $how has a winner, white or black")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $winner and $winner eq "white" || $winner eq "black" 6 333 339
Condition100%6/6
defined $winner and $winner eq "white" || $winner eq "black"
!ll&&!rl&&r
33333
$winner eq "white" or $winner eq "black"
l!l&&r!l&&!r
1811523
MC/DC100%3/3
defined $winner and $winner eq "white" || $winner eq "black"
defined $winner $winner eq "white" $winner eq "black"
Truth table100%4/4
A and B or C
A= defined $winnerB= $winner eq "white"C= $winner eq "black"
ABCresult
0XX0
1000
11X1
1011
30 unless defined $winner && ($winner eq 'white' || $winner eq 'black');
31 }
32 else {
33 41 ▶ Carp::croak("Game::Fanorona::Result: a game ended by $how has no winner")
Branch: 1 branch
BranchTrueFalseTotal
if defined $winner 4 37 41
34 if defined $winner;
35 }
36 370 return;
37 }
38  
39 12 ▶sub is_draw { $DRAWN{ $_[0]->how } ? 1 : 0 }
Subroutine is_draw: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$DRAWN{$_[0]->how} ? : 6 6 12
40  
41 11 ▶sub loser {
Subroutine loser: called CC=3 SCAR=11.0
Pod documented
42 11 my ($self) = @_;
43 11 ▶ my $winner = $self->winner // return undef;
Condition100%2/2
$self->winner // (return undef)
l!l
74
MC/DC100%1/1
$self->winner // (return undef)
$self->winner
Truth table100%2/2
A
A= $self->winner
Aresult
11
00
44 7 ▶ return $winner eq 'white' ? 'black' : 'white';
Branch: 1 branch
BranchTrueFalseTotal
$winner eq 'white' ? : 3 4 7
45 }
46  
47 1 ▶sub ways { (sort(keys %WON), sort(keys %DRAWN)) }
Subroutine ways: called CC=1 SCAR=0.0
Pod documented
48  
49 26 1;
50  
51 __END__
« blib/lib/Game/Fanorona/Bot.pm ↑ Summary blib/lib/Game/Fanorona.pm »