Reversi/Result.pm

filter: Statementstmt 78.7% 26 / 33 Branchbran 50.0% 6 / 12 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 75.0% 6 / 8 Podpod 75.0% 3 / 4 totaltotal 71.4% 50 / 70 CC 10 SCAR 19.6
CC
10
Cov
72%
stringify
20.0
BUILD
5.0
natural
3.0
CRAP 7.1
« Reversi/Board.pm ↑ Summary Reversi/Notation.pm »
1 package Game::Reversi::Result;
2  
3 14 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
5  
6 14 ▶use Object::Proto::Sugar -types;
Subroutine __ANON__: called CC=1 SCAR=0.0
7  
8 14 our $VERSION = '0.04';
9  
10 14 our @RESULTS;
11  
12 14 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 @RESULTS = qw/score draw timeout abandoned resign/;
14 }
15  
16 has winner => (
17 is => 'ro'
18 14 );
19  
20 has result => (
21 is => 'ro',
22 isa => Str
23 14 );
24  
25 has counts => (
26 is => 'ro',
27 isa => HashRef
28 14 );
29  
30 has score => (
31 is => 'ro'
32 14 );
33  
34 has places => (
35 is => 'ro',
36 isa => HashRef
37 14 );
38  
39 396 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
40 396 my ($self) = @_;
41 396 ▶ my $result = $self->result // '';
Condition50%1/2
$self->result // ""
l!l
3960
MC/DC0%0/1
$self->result // ""
$self->result
Truth table50%1/2
A
A= $self->result
Aresult
11
00
42 die "Game::Reversi::Result: '$result' is not a result"
43 396 ▶ unless grep { $_ eq $result } @RESULTS;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $result;} @Game::Reversi::Result::RESULTS 1 395 396
44 395 ▶ die 'Game::Reversi::Result: a draw has no winner'
Branch: 1 branch
BranchTrueFalseTotal
if $result eq "draw" and defined $self->winner 1 394 395
Condition100%3/3
$result eq "draw" and defined $self->winner
!ll&&!rl&&r
378161
MC/DC100%2/2
$result eq "draw" and defined $self->winner
$result eq "draw" defined $self->winner
Truth table100%3/3
A and B
A= $result eq "draw"B= defined $self->winner
ABresult
0X0
100
111
45 if $result eq 'draw' && defined $self->winner;
46 394 return $self;
47 }
48  
49 0 ▶sub results { return [ @RESULTS ] }
Subroutine results: not called CC=1 SCAR=6.9
Pod documented
50  
51 25 ▶sub natural {
Subroutine natural: called CC=3 SCAR=11.1
Pod documented
52 25 my ($self) = @_;
53 25 ▶ return ($self->result eq 'score' || $self->result eq 'draw') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->result eq 'score' || $self->result eq 'draw' ? : 14 11 25
Condition66%2/3
$self->result eq "score" or $self->result eq "draw"
l!l&&r!l&&!r
14011
MC/DC50%1/2
$self->result eq "score" or $self->result eq "draw"
$self->result eq "score" $self->result eq "draw"
Truth table66%2/3
A or B
A= $self->result eq "score"B= $self->result eq "draw"
ABresult
1X1
011
000
54 }
55  
56 0 ▶sub stringify {
Subroutine stringify: not called CC=4 SCAR=30.0
Pod documented
57 0 my ($self) = @_;
58 0 my $score = $self->score;
59 0 ▶ my $line = defined $self->winner ? uc($self->winner) . ' wins' : 'a tie';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->winner ? : 0 0 0
60 0 ▶ $line .= ', ' . $score->{b} . ' to ' . $score->{w} if $score;
Branch: 1 branch
BranchTrueFalseTotal
if $score 0 0 0
61 0 ▶ $line .= ' (' . $self->result . ')' unless $self->natural;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->natural 0 0 0
62 0 return $line;
63 }
64  
65 14 1;
66  
67 __END__
« Reversi/Board.pm ↑ Summary Reversi/Notation.pm »