blib/lib/Game/Oware/Result.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 62.5% 10 / 16 Conditioncond 70.9% 22 / 31 MC/DCmcdc 11.7% 2 / 17 Subroutinesub 75.0% 6 / 8 Podpod 80.0% 4 / 5 totaltotal 71.0% 86 / 121 CC 21 SCAR 24.6
CC
21
Cov
81%
BUILD
19.3
stringify
4.1
natural
4.0
CRAP 11.7
↑ Summary blib/lib/Game/Oware/Move.pm »
1 package Game::Oware::Result;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 our $VERSION = '0.03';
9  
10 17 our @RESULTS = qw/ score draw timeout abandoned resign /;
11  
12 17 our @REASONS = qw/ target even no_feed cycle timeout abandon resign /;
13  
14 17 my %IS_RESULT = map { $_ => 1 } @RESULTS;
15 17 my %IS_REASON = map { $_ => 1 } @REASONS;
16  
17 17 has winner => (is => 'ro');
18  
19 has result => (
20 is => 'ro',
21 isa => Str
22 17 );
23  
24 has reason => (
25 is => 'ro',
26 isa => Str
27 17 );
28  
29 has captured => (
30 is => 'ro',
31 isa => HashRef,
32 default => {}
33 17 );
34  
35 17 has score => (is => 'ro');
36  
37 has places => (
38 is => 'ro',
39 isa => HashRef,
40 default => {}
41 17 );
42  
43 48 ▶sub BUILD {
Subroutine BUILD: called CC=15 SCAR=29.6
Pod undocumented
44 48 my ($self) = @_;
45  
46 48 ▶ my $result = $self->result // '';
Condition50%1/2
$self->result // ""
l!l
480
MC/DC0%0/1
$self->result // ""
$self->result
Truth table50%1/2
A
A= $self->result
Aresult
11
00
47 die "Game::Oware::Result: '$result' is not a result"
48 48 ▶ unless $IS_RESULT{$result};
Branch: 1 branch
BranchTrueFalseTotal
unless $IS_RESULT{$result} 0 48 48
49  
50 48 ▶ my $reason = $self->reason // '';
Condition50%1/2
$self->reason // ""
l!l
480
MC/DC0%0/1
$self->reason // ""
$self->reason
Truth table50%1/2
A
A= $self->reason
Aresult
11
00
51 die "Game::Oware::Result: '$reason' is not a reason"
52 48 ▶ unless $IS_REASON{$reason};
Branch: 1 branch
BranchTrueFalseTotal
unless $IS_REASON{$reason} 0 48 48
53  
54 48 my $winner = $self->winner;
55 48 ▶ die 'Game::Oware::Result: a draw has no winner'
Branch: 1 branch
BranchTrueFalseTotal
if $result eq "draw" and defined $winner 0 48 48
Condition66%2/3
$result eq "draw" and defined $winner
!ll&&!rl&&r
4080
MC/DC0%0/2
$result eq "draw" and defined $winner
$result eq "draw" defined $winner
Truth table66%2/3
A and B
A= $result eq "draw"B= defined $winner
ABresult
0X0
100
111
56 if $result eq 'draw' && defined $winner;
57 48 ▶ die 'Game::Oware::Result: a decided game has a winner'
Branch: 1 branch
BranchTrueFalseTotal
if $result ne "draw" and $result ne "abandoned" and not defined $winner 0 48 48
Condition83%5/6
$result ne "draw" and $result ne "abandoned" and not defined $winner
!ll&&!rl&&r
9390
$result ne "draw" and $result ne "abandoned"
!ll&&!rl&&r
8139
MC/DC0%0/3
$result ne "draw" and $result ne "abandoned" and not defined $winner
$result ne "draw" $result ne "abandoned" not defined $winner
Truth table75%3/4
A and B and not(C)
A= $result ne "draw"B= $result ne "abandoned"C= not defined $winner
ABCresult
0XX0
10X0
1100
1111
58 if $result ne 'draw' && $result ne 'abandoned' && !defined $winner;
59 48 ▶ die "Game::Oware::Result: '$winner' is not a seat"
Branch: 1 branch
BranchTrueFalseTotal
if defined $winner and $winner ne "p1" and $winner ne "p2" 0 48 48
Condition83%5/6
defined $winner and $winner ne "p1" and $winner ne "p2"
!ll&&!rl&&r
23250
defined $winner and $winner ne "p1"
!ll&&!rl&&r
91425
MC/DC0%0/3
defined $winner and $winner ne "p1" and $winner ne "p2"
defined $winner $winner ne "p1" $winner ne "p2"
Truth table75%3/4
A and B and C
A= defined $winnerB= $winner ne "p1"C= $winner ne "p2"
ABCresult
0XX0
10X0
1100
1111
60 if defined $winner && $winner ne 'p1' && $winner ne 'p2';
61  
62 48 ▶ die 'Game::Oware::Result: only a natural ending has a score'
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->score and not $self->natural 0 48 48
Condition66%2/3
defined $self->score and not $self->natural
!ll&&!rl&&r
12360
MC/DC0%0/2
defined $self->score and not $self->natural
defined $self->score not $self->natural
Truth table66%2/3
A and not(B)
A= defined $self->scoreB= not $self->natural
ABresult
0X0
100
111
63 if defined $self->score && !$self->natural;
64  
65 48 return $self;
66 }
67  
68 39 ▶sub natural {
Subroutine natural: called CC=4 SCAR=13.9
Pod documented
69 39 my ($self) = @_;
70 39 ▶ my $result = $self->result // '';
Condition50%1/2
$self->result // ""
l!l
390
MC/DC0%0/1
$self->result // ""
$self->result
Truth table50%1/2
A
A= $self->result
Aresult
11
00
71 39 ▶ return $result eq 'score' || $result eq 'draw' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$result eq 'score' || $result eq 'draw' ? : 37 2 39
Condition100%3/3
$result eq "score" or $result eq "draw"
l!l&&r!l&&!r
2982
MC/DC100%2/2
$result eq "score" or $result eq "draw"
$result eq "score" $result eq "draw"
Truth table100%3/3
A or B
A= $result eq "score"B= $result eq "draw"
ABresult
1X1
011
000
72 }
73  
74 0 ▶sub results { return [@RESULTS] }
Subroutine results: not called CC=1 SCAR=6.9
Pod documented
75  
76 0 ▶sub reasons { return [@REASONS] }
Subroutine reasons: not called CC=1 SCAR=6.9
Pod documented
77  
78 14 ▶sub stringify {
Subroutine stringify: called CC=4 SCAR=14.1
Pod documented
79 14 my ($self) = @_;
80 14 my $captured = $self->captured;
81 14 ▶ my $line = defined $self->winner
Branch: 1 branch
BranchTrueFalseTotal
defined $self->winner ? : 12 2 14
82 ? $self->winner . ' wins by ' . $self->result
83 : 'a ' . $self->result;
84 14 $line .= ' (' . $self->reason . ')';
85 14 ▶ return $line . ', ' . ($captured->{p1} // 0) . ' to ' . ($captured->{p2} // 0);
Condition50%2/4
$captured->{"p1"} // 0
l!l
140
$captured->{"p2"} // 0
l!l
140
MC/DC0%0/1
$captured->{"p1"} // 0
$captured->{"p1"}
MC/DC0%0/1
$captured->{"p2"} // 0
$captured->{"p2"}
Truth table50%1/2
A
A= $captured->{"p1"}
Aresult
11
00
Truth table50%1/2
A
A= $captured->{"p2"}
Aresult
11
00
86 }
87  
88 17 1;
89  
90 __END__
↑ Summary blib/lib/Game/Oware/Move.pm »